blob: efa86f9e24bf48d8b51d8953fca578fa0c99c86c [file] [log] [blame]
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -06001// XGL tests
2//
3// Copyright (C) 2014 LunarG, Inc.
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included
13// in all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
22
23#ifndef XGLTESTFRAMEWORK_H
24#define XGLTESTFRAMEWORK_H
25
26#include "gtest-1.7.0/include/gtest/gtest.h"
27#include "xglimage.h"
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060028#include "ShaderLang.h"
29#include "GLSL450Lib.h"
Courtney Goeltzenleuchteref5b1162014-10-10 16:29:46 -060030#include "icd-bil.h"
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060031
32#include <stdlib.h>
33#include <stdio.h>
34#include <stdbool.h>
35#include <string.h>
36#include <iostream>
37#include <fstream>
38#include <list>
Courtney Goeltzenleuchter28d33962014-10-27 13:04:37 -060039
40// Can be used by tests to record additional details / description of test
41#define TEST_DESCRIPTION(desc) RecordProperty("description", desc)
42
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060043using namespace std;
44
45class XglTestImageRecord
46{
47public:
48 XglTestImageRecord();
49 XglTestImageRecord(const XglTestImageRecord &);
50 ~XglTestImageRecord();
51 XglTestImageRecord &operator=(const XglTestImageRecord &rhs);
52 int operator==(const XglTestImageRecord &rhs) const;
53 int operator<(const XglTestImageRecord &rhs) const;
54
55 string m_title;
56 void *m_data;
57 unsigned m_data_size;
58 int m_width;
59 int m_height;
60};
61
62class XglTestFramework : public ::testing::Test
63{
64public:
65 XglTestFramework();
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060066 ~XglTestFramework();
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060067
68 static void InitArgs(int *argc, char *argv[]);
69 static void Finish();
70
71 void WritePPM( const char *basename, XglImage *image );
72 void Show(const char *comment, XglImage *image);
73 void RecordImage(XglImage *image);
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060074 bool GLSLtoBIL(const XGL_PIPELINE_SHADER_STAGE shader_type,
75 const char *pshader,
76 std::vector<unsigned int> &bil);
Courtney Goeltzenleuchter54d02cb2014-10-09 09:13:56 -060077 static bool m_use_bil;
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060078
Courtney Goeltzenleuchter5c25faa2014-10-21 15:24:51 -060079 char** ReadFileData(const char* fileName);
80 void FreeFileData(char** data);
81
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060082private:
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060083 int m_compile_options;
84 int m_num_shader_strings;
85 TBuiltInResource Resources;
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060086 void SetMessageOptions(EShMessages& messages);
87 void ProcessConfigFile();
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060088 EShLanguage FindLanguage(const std::string& name);
89 EShLanguage FindLanguage(const XGL_PIPELINE_SHADER_STAGE shader_type);
90 std::string ConfigFile;
91 bool SetConfigFile(const std::string& name);
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060092 static void Reshape( int w, int h );
93 static void Display();
94 static void Key(unsigned char key, int x, int y);
95 static void SpecialKey( int key, int x, int y );
96
97 void InitGLUT(int w, int h);
98
99 static bool m_show_images;
100 static bool m_save_images;
Courtney Goeltzenleuchter54d02cb2014-10-09 09:13:56 -0600101
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -0600102 static std::list<XglTestImageRecord> m_images;
103 static std::list<XglTestImageRecord>::iterator m_display_image;
104 static int m_display_image_idx;
105
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600106 static bool m_glut_initialized;
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -0600107 static int m_window;
108 static int m_width; // Window width
109 static int m_height; // Window height
110};
111
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -0600112class TestEnvironment : public ::testing::Environment
113{
114 public:
115 void SetUp();
116
117 void TearDown();
118};
119
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -0600120#endif // XGLTESTFRAMEWORK_H