blob: becf085ee2482f43df0600473fe5fee3b66b05c2 [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>
39using namespace std;
40
41class XglTestImageRecord
42{
43public:
44 XglTestImageRecord();
45 XglTestImageRecord(const XglTestImageRecord &);
46 ~XglTestImageRecord();
47 XglTestImageRecord &operator=(const XglTestImageRecord &rhs);
48 int operator==(const XglTestImageRecord &rhs) const;
49 int operator<(const XglTestImageRecord &rhs) const;
50
51 string m_title;
52 void *m_data;
53 unsigned m_data_size;
54 int m_width;
55 int m_height;
56};
57
58class XglTestFramework : public ::testing::Test
59{
60public:
61 XglTestFramework();
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060062 ~XglTestFramework();
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060063
64 static void InitArgs(int *argc, char *argv[]);
65 static void Finish();
66
67 void WritePPM( const char *basename, XglImage *image );
68 void Show(const char *comment, XglImage *image);
69 void RecordImage(XglImage *image);
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060070 bool GLSLtoBIL(const XGL_PIPELINE_SHADER_STAGE shader_type,
71 const char *pshader,
72 std::vector<unsigned int> &bil);
Courtney Goeltzenleuchter54d02cb2014-10-09 09:13:56 -060073 static bool m_use_bil;
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060074
75private:
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060076 int m_compile_options;
77 int m_num_shader_strings;
78 TBuiltInResource Resources;
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060079 void SetMessageOptions(EShMessages& messages);
80 void ProcessConfigFile();
81 char** ReadFileData(const char* fileName);
82 void FreeFileData(char** data);
83 EShLanguage FindLanguage(const std::string& name);
84 EShLanguage FindLanguage(const XGL_PIPELINE_SHADER_STAGE shader_type);
85 std::string ConfigFile;
86 bool SetConfigFile(const std::string& name);
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060087 static void Reshape( int w, int h );
88 static void Display();
89 static void Key(unsigned char key, int x, int y);
90 static void SpecialKey( int key, int x, int y );
91
92 void InitGLUT(int w, int h);
93
94 static bool m_show_images;
95 static bool m_save_images;
Courtney Goeltzenleuchter54d02cb2014-10-09 09:13:56 -060096
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060097 static std::list<XglTestImageRecord> m_images;
98 static std::list<XglTestImageRecord>::iterator m_display_image;
99 static int m_display_image_idx;
100
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600101 static bool m_glut_initialized;
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -0600102 static int m_window;
103 static int m_width; // Window width
104 static int m_height; // Window height
105};
106
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -0600107class TestEnvironment : public ::testing::Environment
108{
109 public:
110 void SetUp();
111
112 void TearDown();
113};
114
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -0600115#endif // XGLTESTFRAMEWORK_H