]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
unit-tests for some of the borderline if-def cases
authorAmos Jeffries <amosjeffries@squid-cache.org>
Sat, 18 Sep 2010 09:28:50 +0000 (03:28 -0600)
committerAmos Jeffries <amosjeffries@squid-cache.org>
Sat, 18 Sep 2010 09:28:50 +0000 (03:28 -0600)
compat/testPreCompiler.cc
compat/testPreCompiler.h

index f00d38bb7b792211358bbad14bc122ef5ef1e989..11a42e7a9c066884a42f470e403f1710c6434330 100644 (file)
@@ -64,3 +64,85 @@ testPreCompiler::testIfDef()
     CPPUNIT_ASSERT(undefinedFalse);
     CPPUNIT_ASSERT(!undefinedTrue);
 }
+
+/**
+ * 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
+ * when undefined macros are used in && conditions
+ */
+void
+testPreCompiler::testIfDefAnd()
+{
+    /* Not Defined to exist at all == false - when used in a compound if */
+#undef UNDEFINED_FOO
+#define ONE_FOO 1
+
+#if UNDEFINED_FOO && ONE_FOO
+    bool undefinedAndTrueA = true;
+#else
+    bool undefinedAndTrueA = false;
+#endif
+#if !UNDEFINED_FOO && ONE_FOO
+    bool undefinedAndFalseA = true;
+#else
+    bool undefinedAndFalseA = false;
+#endif
+    CPPUNIT_ASSERT(undefinedAndFalseA);
+    CPPUNIT_ASSERT(!undefinedAndTrueA);
+
+#if ONE_FOO && UNDEFINED_FOO
+    bool undefinedAndTrueB = true;
+#else
+    bool undefinedAndTrueB = false;
+#endif
+#if ONE_FOO && !UNDEFINED_FOO
+    bool undefinedAndFalseB = true;
+#else
+    bool undefinedAndFalseB = false;
+#endif
+    CPPUNIT_ASSERT(undefinedAndFalseB);
+    CPPUNIT_ASSERT(!undefinedAndTrueB);
+}
+
+/**
+ * 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
+ * when undefined macros are used in || conditions
+ */
+void
+testPreCompiler::testIfDefOr()
+{
+    /* Not Defined to exist at all == false - when used in a compound if */
+#undef UNDEFINED_FOO
+#define ZERO_FOO 0
+
+#if UNDEFINED_FOO || ZERO_FOO
+    bool undefinedOrTrueA = true;
+#else
+    bool undefinedOrTrueA = false;
+#endif
+#if !UNDEFINED_FOO || ZERO_FOO
+    bool undefinedOrFalseA = true;
+#else
+    bool undefinedOrFalseA = false;
+#endif
+    CPPUNIT_ASSERT(undefinedOrFalseA);
+    CPPUNIT_ASSERT(!undefinedOrTrueA);
+
+#if ZERO_FOO || UNDEFINED_FOO
+    bool undefinedOrTrueB = true;
+#else
+    bool undefinedOrTrueB = false;
+#endif
+#if ZERO_FOO || !UNDEFINED_FOO
+    bool undefinedOrFalseB = true;
+#else
+    bool undefinedOrFalseB = false;
+#endif
+    CPPUNIT_ASSERT(undefinedOrFalseB);
+    CPPUNIT_ASSERT(!undefinedOrTrueB);
+
+}
+
index 939a98e57b8e48744bc909fd5f34ca1d2f6093f3..5fd391acaf6774dad9194f7d51d17a3d49e3fc58 100644 (file)
@@ -11,10 +11,14 @@ class testPreCompiler : public CPPUNIT_NS::TestFixture
 {
     CPPUNIT_TEST_SUITE( testPreCompiler );
     CPPUNIT_TEST( testIfDef );
+    CPPUNIT_TEST( testIfDefAnd );
+    CPPUNIT_TEST( testIfDefOr );
     CPPUNIT_TEST_SUITE_END();
 
 protected:
     void testIfDef();
+    void testIfDefAnd();
+    void testIfDefOr();
 };
 
 #endif /* SQUID_COMPAT_TESTS_TESTPRECOMPILER_H */