aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-06-04 21:18:29 +0200
committerMattias Andrée <maandree@operamail.com>2014-06-04 21:18:29 +0200
commitc626d574d4974ef3e532b54b27c76dac337425c7 (patch)
treef14c749bbcbe7c48df4c6977dc55e1da5f8c9a7b /src/test
parentsplit out and doc adjustment method functions from test.c (diff)
downloadlibgamma-c626d574d4974ef3e532b54b27c76dac337425c7.tar.gz
libgamma-c626d574d4974ef3e532b54b27c76dac337425c7.tar.bz2
libgamma-c626d574d4974ef3e532b54b27c76dac337425c7.tar.xz
split out and doc error api test
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/test/errors.c88
-rw-r--r--src/test/errors.h29
-rw-r--r--src/test/test.c33
3 files changed, 118 insertions, 32 deletions
diff --git a/src/test/errors.c b/src/test/errors.c
new file mode 100644
index 0000000..a85f7f2
--- /dev/null
+++ b/src/test/errors.c
@@ -0,0 +1,88 @@
+/**
+ * libgamma — Display server abstraction layer for gamma ramp adjustments
+ * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "errors.h"
+
+#include <libgamma.h>
+
+#include <stdio.h>
+#include <errno.h>
+
+
+
+/**
+ * The error API.
+ */
+void error_test(void)
+{
+ int i;
+
+ /* Test that naming and name dereferencing
+ of errors work. Because the mappings in
+ these [`libgamma_value_of_error` and
+ `libgamma_name_of_error`] functions are
+ generated, it should work if and only if
+ one test passes, assumming the errors are
+ unique whihc is tested in the end of this
+ function. */
+ printf("Testing error API using LIBGAMMA_STATE_UNKNOWN:\n");
+ printf(" Expecting %i: %i\n", LIBGAMMA_STATE_UNKNOWN, libgamma_value_of_error("LIBGAMMA_STATE_UNKNOWN"));
+ printf(" Expecting %s: %s\n", "LIBGAMMA_STATE_UNKNOWN", libgamma_name_of_error(LIBGAMMA_STATE_UNKNOWN));
+ printf("\n");
+
+ /* Test that `libgamma_perror` can print
+ libgamma errors and system errors, and
+ handle success in the same with as `perror`. */
+ printf("Testing libgamma_perror:\n");
+ libgamma_perror(" Expecting LIBGAMMA_STATE_UNKNOWN", LIBGAMMA_STATE_UNKNOWN);
+ libgamma_perror(" Expecting a description for ENOMEM", ENOMEM);
+ libgamma_perror(" Expecting a description for successfulness", 0);
+ /* Test that `libgamma_perror` handles
+ `LIBGAMMA_ERRNO_SET` correctly. */
+ libgamma_perror(" Expecting a description for ENOMEM", (errno = ENOMEM, LIBGAMMA_ERRNO_SET));
+ /* That that `libgamma_perror` handles
+ `LIBGAMMA_DEVICE_REQUIRE_GROUP`
+ correctly both when the required
+ group's name is known and when it
+ is unknown. */
+ libgamma_group_gid = 10;
+ libgamma_group_name = "test";
+ libgamma_perror(" Expecting 'LIBGAMMA_DEVICE_REQUIRE_GROUP: test (10)'", LIBGAMMA_DEVICE_REQUIRE_GROUP);
+ libgamma_group_name = NULL;
+ libgamma_perror(" Expecting 'LIBGAMMA_DEVICE_REQUIRE_GROUP: 10'", LIBGAMMA_DEVICE_REQUIRE_GROUP);
+ printf("\n");
+
+ /* That all libgamma error codes
+ are unique. This is done by
+ getting the name associated
+ with an error code and the getting
+ the error code associated that
+ name and test that the same
+ error code is returned as put in,
+ for each libgamma error code. */
+ printf("Testing error code uniqueness: ");
+ for (i = -1; i >= LIBGAMMA_ERROR_MIN; i--)
+ if (libgamma_value_of_error(libgamma_name_of_error(i)) != i)
+ {
+ printf("failed\n");
+ goto not_unique;
+ }
+ printf("passed\n");
+ not_unique:
+ printf("\n");
+}
+
diff --git a/src/test/errors.h b/src/test/errors.h
new file mode 100644
index 0000000..558b5f9
--- /dev/null
+++ b/src/test/errors.h
@@ -0,0 +1,29 @@
+/**
+ * libgamma — Display server abstraction layer for gamma ramp adjustments
+ * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef LIBGAMMA_TEST_ERRROS_H
+#define LIBGAMMA_TEST_ERRROS_H
+
+
+/**
+ * The error API.
+ */
+void error_test(void);
+
+
+#endif
+
diff --git a/src/test/test.c b/src/test/test.c
index 99a84b1..ccb80c0 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -17,6 +17,7 @@
*/
#include "update-warnings.h"
#include "methods.h"
+#include "errors.h"
#include <libgamma.h>
@@ -28,38 +29,6 @@
-
-static void error_test(void)
-{
- int i;
- printf("Testing error API using LIBGAMMA_STATE_UNKNOWN:\n");
- printf(" Expecting %i: %i\n", LIBGAMMA_STATE_UNKNOWN, libgamma_value_of_error("LIBGAMMA_STATE_UNKNOWN"));
- printf(" Expecting %s: %s\n", "LIBGAMMA_STATE_UNKNOWN", libgamma_name_of_error(LIBGAMMA_STATE_UNKNOWN));
- printf("\n");
- printf("Testing libgamma_perror:\n");
- libgamma_perror(" Expecting LIBGAMMA_STATE_UNKNOWN", LIBGAMMA_STATE_UNKNOWN);
- libgamma_perror(" Expecting a description for ENOMEM", ENOMEM);
- libgamma_perror(" Expecting a description for successfulness", 0);
- libgamma_perror(" Expecting a description for ENOMEM", (errno = ENOMEM, LIBGAMMA_ERRNO_SET));
- libgamma_group_gid = 10;
- libgamma_group_name = "test";
- libgamma_perror(" Expecting 'LIBGAMMA_DEVICE_REQUIRE_GROUP: test (10)'", LIBGAMMA_DEVICE_REQUIRE_GROUP);
- libgamma_group_name = NULL;
- libgamma_perror(" Expecting 'LIBGAMMA_DEVICE_REQUIRE_GROUP: 10'", LIBGAMMA_DEVICE_REQUIRE_GROUP);
- printf("\n");
- printf("Testing error code uniqueness: ");
- for (i = -1; i >= LIBGAMMA_ERROR_MIN; i--)
- if (libgamma_value_of_error(libgamma_name_of_error(i)) != i)
- {
- printf("failed\n");
- goto not_unique;
- }
- printf("passed\n");
- not_unique:
- printf("\n");
-}
-
-
static int select_monitor(libgamma_site_state_t* restrict site_state,
libgamma_partition_state_t* restrict part_state,
libgamma_crtc_state_t* restrict crtc_state)