Browse code

Add implementation

Robert Cranston authored on 15/03/2021 19:32:43
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,51 @@
1
+#include <cerrno>
2
+#include <cstring>
3
+#include <fstream>
4
+#include <stdexcept>
5
+#include <string>
6
+
7
+#include <GL/glew.h>
8
+
9
+#include <glbackend.hpp>
10
+#include <gltest.hpp>
11
+
12
+
13
+// Function that throws with a system-supplied message.
14
+void file_open(std::string const & filename)
15
+{
16
+    auto file = std::ifstream{"nonexistent"};
17
+    if (!file)
18
+        throw std::runtime_error(std::string{} +
19
+            "Could not open file '" + filename + "':\n" +
20
+            std::strerror(errno) + "." // NOLINT
21
+        );
22
+}
23
+
24
+
25
+GLTEST(gltest, 640, 480, 2, 0)
26
+{
27
+    backend.prefix("assets/tests");
28
+
29
+    GLTEST_EXPECT_VALUE(
30
+        GL_FALSE,
31
+        glIsEnabled(GL_DEPTH_TEST)
32
+    )
33
+    GLTEST_EXPECT_EXCEPTION(false,
34
+        "Expected exception",
35
+        throw std::runtime_error("Expected exception")
36
+    )
37
+    GLTEST_EXPECT_EXCEPTION(true,
38
+        "Could not open file 'nonexistent':\n",
39
+        // "No such file or directory"
40
+        file_open("nonexistent")
41
+    )
42
+
43
+    constexpr auto size = 0.5;
44
+    glBegin(GL_TRIANGLE_STRIP);
45
+    glVertex3f(-size, -size, 0);
46
+    glVertex3f(-size, +size, 0);
47
+    glVertex3f(+size, -size, 0);
48
+    glVertex3f(+size, +size, 0);
49
+    glEnd();
50
+    backend.tga_compare("GLTest.tga");
51
+}