]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
UnitTests: check precompiler is sane with our wrapping style.
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 9 Nov 2009 09:27:59 +0000 (22:27 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 9 Nov 2009 09:27:59 +0000 (22:27 +1300)
compat/Makefile.am
compat/testPreCompiler.cc [new file with mode: 0644]
compat/testPreCompiler.h [new file with mode: 0644]

index 3aa5b9751bfc3534e776622a8e03f0449f5e490a..82326f1961bf4d97e7105d2bb8281edb68ae40f0 100644 (file)
@@ -42,6 +42,15 @@ libcompat_la_SOURCES = \
        GnuRegex.h \
        GnuRegex.c
 
+check_PROGRAMS += testPreCompiler
+TESTS += testPreCompiler
+
+testPreCompiler_SOURCES= \
+       testPreCompiler.h \
+       testPreCompiler.cc \
+       $(top_srcdir)/src/tests/testMain.cc
+testPreCompiler_LDADD= @SQUID_CPPUNIT_LA@ @SQUID_CPPUNIT_LIBS@
+testPreCompiler_LDFLAGS=
 
 # os/ subdir prevents us using src/TestHeaders.am
 #
diff --git a/compat/testPreCompiler.cc b/compat/testPreCompiler.cc
new file mode 100644 (file)
index 0000000..b939f8e
--- /dev/null
@@ -0,0 +1,65 @@
+#include "config.h"
+
+#if HAVE_ASSERT_H
+#include <assert.h>
+#endif
+
+#include "testPreCompiler.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( testPreCompiler );
+
+/**
+ * Test several ways of defining pre-compiler directives.
+ * Squid-3 uses #if FOO syntax for precompiler directives.
+ * These tests ensure that the inputs will work as expected.
+ */
+void
+testPreCompiler::testIfDef()
+{
+    /* Defined to explicit value 1 should be true */
+#define ONE_FOO 1
+#if ONE_FOO
+    bool oneTrue = true;
+#else
+    bool oneTrue = false;
+#endif
+#if !ONE_FOO
+    bool oneFalse = true;
+#else
+    bool oneFalse = false;
+#endif
+    CPPUNIT_ASSERT(oneTrue);
+    CPPUNIT_ASSERT(!oneFalse);
+
+    /* Defined to explicit value 0 should be false */
+#define ZERO_FOO 0
+#if ZERO_FOO
+    bool zeroTrue = true;
+#else
+    bool zeroTrue = false;
+#endif
+#if !ZERO_FOO
+    bool zeroFalse = true;
+#else
+    bool zeroFalse = false;
+#endif
+    CPPUNIT_ASSERT(zeroFalse);
+    CPPUNIT_ASSERT(!zeroTrue);
+
+    /* Defined to exist without a value generates pre-compiler errors when used in #if . */
+
+    /* Not Defined to exist at all == false */ 
+#undef UNDEFINED_FOO
+#if UNDEFINED_FOO
+    bool undefinedTrue = true;
+#else
+    bool undefinedTrue = false;
+#endif
+#if !UNDEFINED_FOO
+    bool undefinedFalse = true;
+#else
+    bool undefinedFalse = false;
+#endif
+    CPPUNIT_ASSERT(undefinedFalse);
+    CPPUNIT_ASSERT(!undefinedTrue);
+}
diff --git a/compat/testPreCompiler.h b/compat/testPreCompiler.h
new file mode 100644 (file)
index 0000000..939a98e
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef SQUID_COMPAT_TESTS_TESTPRECOMPILER_H
+#define SQUID_COMPAT_TESTS_TESTPRECOMPILER_H
+
+#include <cppunit/extensions/HelperMacros.h>
+
+/*
+ * Test the pre-compiler directives used within Squid code actually work.
+ */
+
+class testPreCompiler : public CPPUNIT_NS::TestFixture
+{
+    CPPUNIT_TEST_SUITE( testPreCompiler );
+    CPPUNIT_TEST( testIfDef );
+    CPPUNIT_TEST_SUITE_END();
+
+protected:
+    void testIfDef();
+};
+
+#endif /* SQUID_COMPAT_TESTS_TESTPRECOMPILER_H */