From eef37c44a7ab980e3ebc35987518cc0a7b1965ee Mon Sep 17 00:00:00 2001
From: Jeremy Whiting <jeremy.whiting@collabora.com>
Date: Wed, 14 Aug 2019 09:27:04 -0600
Subject: [PATCH] Added mock-graphics to give specified json output for
 testing.

In order to test SrtGraphics on CI systems that likely aren't running
X we needed a mock-graphics to return most of what wflinfo gives in
different settings.

Use mock-bad-wflinfo, mock-good-wflinfo and mock-software-wflinfo
in srt_check_graphics.

Use mock-good-wflinfo for good output, mock-bad-wflinfo for
error output and mock-software-wflinfo for software rendering
test output.
---
 tests/meson.build             | 21 ++++++++++++++++++
 tests/mock-bad-wflinfo.c      | 36 ++++++++++++++++++++++++++++++
 tests/mock-good-wflinfo.c     | 41 +++++++++++++++++++++++++++++++++++
 tests/mock-software-wflinfo.c | 39 +++++++++++++++++++++++++++++++++
 4 files changed, 137 insertions(+)
 create mode 100644 tests/mock-bad-wflinfo.c
 create mode 100644 tests/mock-good-wflinfo.c
 create mode 100644 tests/mock-software-wflinfo.c

diff --git a/tests/meson.build b/tests/meson.build
index 5e5f11f2e..a8deb031c 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -93,4 +93,25 @@ foreach test_name : tests
   endif
 endforeach
 
+executable(
+  'mock-good-wflinfo',
+  'mock-good-wflinfo.c',
+  install: true,
+  install_dir : tests_dir
+)
+
+executable(
+  'mock-bad-wflinfo',
+  'mock-bad-wflinfo.c',
+  install: true,
+  install_dir : tests_dir
+)
+
+executable(
+  'mock-software-wflinfo',
+  'mock-software-wflinfo.c',
+  install: true,
+  install_dir : tests_dir
+)
+
 # vim:set sw=2 sts=2 et:
diff --git a/tests/mock-bad-wflinfo.c b/tests/mock-bad-wflinfo.c
new file mode 100644
index 000000000..2311ddb83
--- /dev/null
+++ b/tests/mock-bad-wflinfo.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2019 Collabora Ltd.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+
+int
+main (int argc,
+      char **argv)
+{
+  // Give bad output
+  fprintf (stderr, "Waffle error: 0x2 WAFFLE_ERROR_UNKNOWN: XOpenDisplay failed\n");
+  return 1;
+}
+
diff --git a/tests/mock-good-wflinfo.c b/tests/mock-good-wflinfo.c
new file mode 100644
index 000000000..9be7fabd8
--- /dev/null
+++ b/tests/mock-good-wflinfo.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright © 2019 Collabora Ltd.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+
+void usage(void);
+
+int
+main (int argc,
+      char **argv)
+{
+  // Give good output
+  printf ("{\n\t\"waffle\": {\n\t\t\"platform\": \"glx\",\n\t\t\"api\": \"gl\"\n\t},\n\t\"OpenGL\": {\n\t\t\"vendor string\": \"Intel Open Source Technology Center\",\n"
+          "\t\t\"renderer string\": \"Mesa DRI Intel(R) Haswell Desktop \",\n\t\t\"version string\": \"3.0 Mesa 19.1.3\",\n\t\t\"shading language version string\": \"1.30\",\n"
+          "\t\t\"extensions\": [\n"
+          "\t\t]\n\t}\n}\n");
+  return 0;
+}
+
diff --git a/tests/mock-software-wflinfo.c b/tests/mock-software-wflinfo.c
new file mode 100644
index 000000000..7814889e0
--- /dev/null
+++ b/tests/mock-software-wflinfo.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright © 2019 Collabora Ltd.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+
+int
+main (int argc,
+      char **argv)
+{
+  // Give software renderer output
+  printf ("{\n\t\"waffle\": {\n\t\t\"platform\": \"glx\",\n\t\t\"api\": \"gl\"\n\t\t},\n\t\"OpenGL\": {\n\t\t\"vendor string\": \"VMware, Inc.\",\n"
+          "\t\t\"renderer string\": \"llvmpipe (LLVM 8.0, 256 bits)\",\n\t\t\"version string\": \"3.1 Mesa 19.1.3\",\n\t\t\"shading language version string\": \"1.40\",\n"
+          "\t\t\"extensions\": [\n"
+          "\t\t]\n\t}\n}\n");
+  return 0;
+}
+
-- 
GitLab