<commit_before>#![feature(plugin)]
#![feature(unboxed_closures)]
#![plugin(glium_macros)]

extern crate glutin;

#[macro_use]
extern crate glium;

use std::default::Default;
use glium::Surface;

mod support;

#[test]
fn texture_2d_draw() {    
    let display = support::build_display();
    let (vb, ib) = support::build_rectangle_vb_ib(&display);

    let texture = glium::texture::Texture2d::new(&display, vec![
        vec![(255, 0, 0, 255), (255, 0, 0, 255)],
        vec![(255, 0, 0, 255), (255, 0, 0, 255u8)],
    ]);

    let program = glium::Program::from_source(&display,
        "
            #version 110

            attribute vec2 position;

            void main() {
                gl_Position = vec4(position, 0.0, 1.0);
            }
        ",
        "
            #version 110

            uniform sampler2D texture;

            void main() {
                gl_FragColor = texture2D(texture, vec2(0.5, 0.5));
            }
        ",
        None).unwrap();

    let output = support::build_renderable_texture(&display);
    output.as_surface().clear_color(0.0, 0.0, 0.0, 0.0);
    output.as_surface().draw(&vb, &ib, &program, &uniform!{ texture: &texture },
                             &Default::default()).unwrap();

    let data: Vec<Vec<(f32, f32, f32, f32)>> = output.read();
    for row in data.iter() {
        for pixel in row.iter() {
            assert_eq!(pixel, &(1.0, 0.0, 0.0, 1.0));
        }
    }

    display.assert_no_error();
}

#[test]
fn compressed_texture_2d_draw() {    
    let display = support::build_display();
    let (vb, ib) = support::build_rectangle_vb_ib(&display);

    let texture = glium::texture::CompressedTexture2d::new(&display, vec![
        vec![(255, 0, 0, 255), (255, 0, 0, 255)],
        vec![(255, 0, 0, 255), (255, 0, 0, 255u8)],
    ]);

    let program = glium::Program::from_source(&display,
        "
            #version 110

            attribute vec2 position;

            void main() {
                gl_Position = vec4(position, 0.0, 1.0);
            }
        ",
        "
            #version 110

            uniform sampler2D texture;

            void main() {
                gl_FragColor = texture2D(texture, vec2(0.5, 0.5));
            }
        ",
        None).unwrap();

    let output = support::build_renderable_texture(&display);
    output.as_surface().clear_color(0.0, 0.0, 0.0, 0.0);
    output.as_surface().draw(&vb, &ib, &program, &uniform!{ texture: &texture },
                             &Default::default()).unwrap();

    let data: Vec<Vec<(f32, f32, f32, f32)>> = output.read();
    for row in data.iter() {
        for pixel in row.iter() {
            assert_eq!(pixel, &(1.0, 0.0, 0.0, 1.0));
        }
    }

    display.assert_no_error();
}<commit_msg>Use macros in tests/texture_draw.rs<commit_after>#![feature(plugin)]
#![feature(unboxed_closures)]
#![plugin(glium_macros)]

extern crate glutin;

#[macro_use]
extern crate glium;

use std::default::Default;
use glium::Surface;

mod support;

macro_rules! texture_draw_test {
    ($test_name:ident, $tex_ty:ident, $sampler_ty:expr, $fun:expr, $coords:expr, $data:expr) => (
        #[test]
        fn $test_name() {
            let display = support::build_display();
            let (vb, ib) = support::build_rectangle_vb_ib(&display);

            let texture = glium::texture::$tex_ty::new(&display, vec![
                vec![(255, 0, 0, 255), (255, 0, 0, 255)],
                vec![(255, 0, 0, 255), (255, 0, 0, 255u8)],
            ]);

            let program = glium::Program::from_source(&display,
                "
                    #version 110

                    attribute vec2 position;

                    void main() {
                        gl_Position = vec4(position, 0.0, 1.0);
                    }
                ",
                format!("
                    #version 110

                    uniform {} texture;

                    void main() {{
                        gl_FragColor = {}(texture, {});
                    }}
                ", $sampler_ty, $fun, $coords).as_slice(),
                None).unwrap();

            let output = support::build_renderable_texture(&display);
            output.as_surface().clear_color(0.0, 0.0, 0.0, 0.0);
            output.as_surface().draw(&vb, &ib, &program, &uniform!{ texture: &texture },
                                     &Default::default()).unwrap();

            let data: Vec<Vec<(f32, f32, f32, f32)>> = output.read();
            for row in data.iter() {
                for pixel in row.iter() {
                    assert_eq!(pixel, &(1.0, 0.0, 0.0, 1.0));
                }
            }

            display.assert_no_error();
        }
    );
}

texture_draw_test!(texture_2d_draw, Texture2d, "sampler2D", "texture2D", "vec2(0.5, 0.5)",
    vec![
        vec![(255, 0, 0, 255), (255, 0, 0, 255)],
        vec![(255, 0, 0, 255), (255, 0, 0, 255u8)],
    ]);

texture_draw_test!(compressed_texture_2d_draw, CompressedTexture2d, "sampler2D", "texture2D",
    "vec2(0.5, 0.5)",
    vec![
        vec![(255, 0, 0, 255), (255, 0, 0, 255)],
        vec![(255, 0, 0, 255), (255, 0, 0, 255u8)],
    ]);
{'fraction_non_alphanumeric': 0.16502033701336433, 'fraction_numerical': 0.05984892504357931, 'mean_word_length': 1.9076576576576576, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7111592', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1670, 'n_words': 363}