Commits

Palmer, 2E0EOL committed 1233563 Draft

Add unit testing for the v_or() macro

Comments (0)

Files changed (3)

 INCLUDES = \
   -I.
 
+TESTS = tests1
+check_PROGRAMS = $(TESTS)
+
 lib_LTLIBRARIES = libdlstds.la
 libdlstds_la_SOURCES  = coordins.cpp
+tests1_LDADD = -ldlstds -lcunit
 
 nobase_include_HEADERS  = dlstdinc.h
 nobase_include_HEADERS += dlstdinc_datetime.h
 Section: libs
 Priority: extra
 Maintainer: David Palmer <palmer@overchat.org>
-Build-Depends: debhelper (>= 7), autoconf, autotools-dev, automake, libtool
+Build-Depends: debhelper (>= 7), autoconf, autotools-dev, automake, libtool, libcunit1-dev
 Standards-Version: 3.7.3
 Homepage: http://www.daybologic.co.uk/software.php?content=dlstds
 Vcs-Browser: https://bitbucket.org/daybologic/dlstds
+/*
+ Daybo Logic Standard Inclusions
+ Copyright (C) 1998-2013 Daybo Logic.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the project nor the names of its contributors
+    may be used to endorse or promote products derived from this software
+    without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+*/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif /*HAVE_CONFIG_H*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <unistd.h>
+
+#include "CUnit/Basic.h"
+#ifdef HDRSTOP
+# pragma hdrstop
+#endif /*HDRSTOP*/
+
+#include "dlstdinc.h"
+
+#define DIE(m) Die((__FILE__), (__LINE__), (m))
+
+enum testResultType {
+	TEST_FAIL = 1,
+	TEST_OK = 0
+};
+/*-------------------------------------------------------------------------*/
+int main(int argc, char *argv[]);
+
+/* Suite initialisation routines */
+static int init_suite_macro(void); /* Core library implementation testing: dpcrtlmm.c  */
+
+/* Suite cleanup routines */
+static int clean_suite_macro(void);
+
+/* This function aborts the program under extraordinary circumstances */
+static void Die(const char *File, const unsigned int Line, const char *Message);
+
+/* Test suite macro */
+static void suite_core_Ver(void);
+static void suite_macro_V_OR(void);
+/*-------------------------------------------------------------------------*/
+static int init_suite_macro()
+{
+	return 0;
+}
+/*-------------------------------------------------------------------------*/
+static int clean_suite_macro()
+{
+	return 0;
+}
+/*-------------------------------------------------------------------------*/
+static void Die(const char *File, const unsigned int Line, const char *Message)
+{
+	unsigned int l = strlen(Message);
+	if ( l && l-1 == '\n' ) {
+		fprintf(stderr, "%s", Message);
+	} else {
+		fprintf(stderr, "%s at line %u in %s\n", File, Line, Message);
+	}
+	abort();
+}
+/*-------------------------------------------------------------------------*/
+int main(int argc, char *argv[])
+{
+	CU_ErrorCode err;
+	unsigned int failCount;
+	size_t testI, suiteI;
+
+	static struct {
+		const char *TestName;
+		void (*TestFunc)(void);
+	} MacroTests[] = {
+		{ "V_OR",
+		  &suite_macro_V_OR
+		}
+	};
+
+	/* Suites */
+	static struct {
+		const char *SuiteName;
+		int (*Init)(void);
+		int (*Clean)(void);
+	} Suites[] = {
+		{ "suite_macro", &init_suite_macro, &clean_suite_macro }
+	};
+
+	CU_pSuite pSuite[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+
+	/* initialize the CUnit test registry */
+	if ( CU_initialize_registry() != CUE_SUCCESS )
+		return CU_get_error();
+
+	/* Add all suites to the registry */
+	for ( suiteI = 0U; suiteI < sizeof(Suites)/sizeof(Suites[0]); suiteI++ ) {
+		pSuite[suiteI] = CU_add_suite(Suites[suiteI].SuiteName, Suites[suiteI].Init, Suites[suiteI].Clean);
+		if ( !pSuite[suiteI] ) {
+			CU_cleanup_registry();
+			return CU_get_error();
+		}
+	}
+	suiteI = 0U;
+
+	/* add the tests to the suites */
+	for ( testI = 0; testI < sizeof(MacroTests)/sizeof(MacroTests[0]); testI++ ) {
+		if ( !CU_add_test(pSuite[suiteI], MacroTests[testI].TestName, MacroTests[testI].TestFunc) ) {
+			CU_cleanup_registry();
+			return CU_get_error();
+		}
+	}
+	/*suiteI++;*/ /* Don't forget to uncomment this before adding more tests */
+
+	/* Run all tests using the CUnit Basic interface */
+	CU_basic_set_mode(CU_BRM_VERBOSE);
+	CU_basic_run_tests();
+	failCount = CU_get_number_of_failure_records();
+	CU_cleanup_registry();
+	err = CU_get_error();
+	if ( err != CUE_SUCCESS ) return err;
+	if ( failCount ) return EXIT_FAILURE;
+	return EXIT_SUCCESS;
+}
+/*-------------------------------------------------------------------------*/
+static void suite_macro_V_OR()
+{
+	CU_ASSERT_EQUAL(V_OR(9, 0), 9);
+	CU_ASSERT_EQUAL(V_OR(9, 5), 9);
+	CU_ASSERT_EQUAL(V_OR(5, 9), 5);
+	CU_ASSERT_EQUAL(V_OR(5, 0), 5);
+	CU_ASSERT_EQUAL(V_OR(NULL, 10), 10);
+	CU_ASSERT_EQUAL(V_OR(NULL, NULL), NULL);
+	CU_ASSERT_EQUAL(V_OR(0, 0), 0);
+}
+/*-------------------------------------------------------------------------*/