Permalink
Browse files

Changed to version to 1.0-beta, fixed assertions, added new assertion…

…s for floats/not equals, fixed Makefile for distcheck
  • Loading branch information...
1 parent b36306b commit 5cd7c5ffed8d7accb0a3aaff405d0a52c24125d6 @jecklgamis committed Mar 11, 2013
View
@@ -2,11 +2,11 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.53)
-AC_INIT([rcunit],[1.0],[jecklgamis@gmail.com])
+AC_INIT([rcunit],[1.0-beta],[jecklgamis@gmail.com])
AC_CANONICAL_HOST
AC_PROG_MAKE_SET
AC_CONFIG_SRCDIR([src/rcunit.c])
-AM_INIT_AUTOMAKE([rcunit],[1.0])
+AM_INIT_AUTOMAKE
# Configuration header
AC_CONFIG_HEADER(src/rcunit_config_env.h)
View
@@ -19,3 +19,7 @@ rcunit_sample_app_demo_SOURCES = rcunit_sample_app_demo.c
LDADD = ../src/librcunit.a
AM_CPPFLAGS = -I $(top_srcdir)/src -I $(srcdir)
+
+clean-local:
+ rm -f *.log
+ rm -f rcunit_test_run_report.*
@@ -1,6 +0,0 @@
-#include <rcunit.h>
-
-int main(int argc,char **argv){
- fprintf(stdout,"Please execute the binaries rcunit_sample_app_X\n");
- return(0);
-}
View
@@ -33,7 +33,7 @@
extern void rcu_assert_impl(int cond, const char *filename, const char *func_name, int line,
const char *format, ...);
-/* Asserts a condition */
+/* Asserts a true condition */
#define RCU_ASSERT(cond) \
{ rcu_assert_impl((cond), __FILE__,__func__, __LINE__, "%s", #cond); }
@@ -53,16 +53,37 @@ extern void rcu_assert_impl(int cond, const char *filename, const char *func_nam
#define RCU_ASSERT_NOT_NULL(ptr) \
{ rcu_assert_impl(((ptr) != NULL), __FILE__,__func__,__LINE__,"expecting non-null pointer"); }
-/* Asserts that the two variables are equal */
+/* Asserts that the two values/variables are equal (integer types) */
#define RCU_ASSERT_EQUAL(expected, actual) \
- { int __expected = expected; int __actual = actual; \
- rcu_assert_impl((__expected == __actual), __FILE__,__func__, __LINE__,"%s expected to be %s but got %d", #actual, #expected, __actual); \
+ { long __expected = expected; long __actual = actual; \
+ rcu_assert_impl((__expected == __actual), __FILE__,__func__, __LINE__,"%s expected to be %s but got %ld", #actual, #expected, (long)__actual); \
+ }
+
+/* Asserts that the two values/variables are not equal (integer types) */
+#define RCU_ASSERT_NOT_EQUAL(expected, actual) \
+ { long __expected = expected; long __actual = actual; \
+ rcu_assert_impl((__expected != __actual), __FILE__,__func__, __LINE__,"%s not expected to be %s but got %ld", #actual, #expected, (long)__actual); \
+ }
+
+#define RCU_ASSERT_EQUAL_FLOATS(expected, actual) \
+ { double __expected = expected; double __actual = actual; \
+ rcu_assert_impl((__expected == __actual), __FILE__,__func__, __LINE__,"%s expected to be %s but got %lf", #actual, #expected, (double)__actual); \
+ }
+
+#define RCU_ASSERT_NOT_EQUAL_FLOATS(expected, actual) \
+ { double __expected = expected; double __actual = actual; \
+ rcu_assert_impl((__expected != __actual), __FILE__,__func__, __LINE__,"%s not expected to be %s but got %lf", #actual, #expected, (double)__actual); \
+ }
+
+#define RCU_ASSERT_EQUAL_PTRS(expected, actual) \
+ { void *__expected = expected; void *__actual = actual; \
+ rcu_assert_impl((__expected == __actual), __FILE__,__func__, __LINE__,"%s expected to be %s but got %p", #actual, #expected, (void*)__actual); \
}
/* Asserts that the two strings are equal */
#define RCU_ASSERT_EQUAL_STRING(expected, actual) \
{ const char *__expected = expected; const char *__actual = actual; \
- rcu_assert_impl( !(strcmp((__expected), (__actual))), __FILE__,__func__, __LINE__, "%s expected to be \"%s\" but got \"%s\"", __expected, __actual); \
+ rcu_assert_impl( !(strcmp((__expected), (__actual))), __FILE__,__func__, __LINE__, "%s expected to be \"%s\" but got \"%s\"", #actual, #expected,__actual); \
}
/* Records an explicitly failed condition described by msg */
@@ -92,7 +92,7 @@
#define PACKAGE_NAME "rcunit"
/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "rcunit 1.0"
+#define PACKAGE_STRING "rcunit 1.0-beta"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "rcunit"
@@ -101,7 +101,7 @@
#define PACKAGE_URL ""
/* Define to the version of this package. */
-#define PACKAGE_VERSION "1.0"
+#define PACKAGE_VERSION "1.0-beta"
/* The size of `int', as computed by sizeof. */
#define SIZEOF_INT 4
@@ -113,7 +113,7 @@
#define STDC_HEADERS 1
/* Version number of package */
-#define VERSION "1.0"
+#define VERSION "1.0-beta"
/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
View
@@ -5,18 +5,25 @@ noinst_PROGRAMS = rcunit_test
rcunit_test_SOURCES = rcunit_test.c testmoko.c testmoko_exception.c
noinst_HEADERS = \
- rcunit_test.c \
+ rcunit_test.h \
rcunit_test_assertions.c \
rcunit_test_exceptions.c \
rcunit_test_framework.c \
rcunit_test_function.c \
rcunit_test_module.c \
rcunit_test_mtrace.c \
- rcunit_test_registry.c
+ rcunit_test_registry.c \
+ testmoko.h \
+ testmoko_exception.h
-LDADD = $(top_srcdir)/src/librcunit.a
+LDADD = ../src/librcunit.a
+AM_CPPFLAGS = -I $(top_srcdir)/src -I $(srcdir)
+
+check : rcunit_test
+ ./rcunit_test
+
+clean-local:
+ rm -f *.log
+ rm -f rcunit_test_run_report.*
-if DEBUG
-else
-endif
View
@@ -26,8 +26,8 @@
#include "rcunit_test.h"
-extern int rcunit_sample_app_main(int argc, char **argv);
-extern int rcunit_sample_app_2_main(int argc, char **argv);
+//extern int rcunit_sample_app_main(int argc, char **argv);
+//extern int rcunit_sample_app_2_main(int argc, char **argv);
RCU_TEST(test) {
RCU_ASSERT(RCU_TRUE);
@@ -86,8 +86,9 @@ TMK_INCLUDE_TEST(rcu_test_run_hooks)
/* assertion macro tests */
TMK_INCLUDE_TEST(rcu_test_assert_single_evaluation)
TMK_INCLUDE_TEST(rcu_test_bit_assertions)
-TMK_INCLUDE_TEST(rcu_test_byte_array_assertions)
-
+TMK_INCLUDE_TEST(rcu_test_byte_assertions)
+TMK_INCLUDE_TEST(rcu_test_float_assertions)
+TMK_INCLUDE_TEST(rcu_test_pointer_assertions)
/* memory allocation tracing tests */
TMK_INCLUDE_TEST( rcu_test_mtrace)
View
@@ -27,6 +27,8 @@
#ifndef RCUNIT_TEST_H
#define RCUNIT_TEST_H
+#include <stdlib.h>
+#include <stdio.h>
#include "rcunit.h"
#include "testmoko.h"
@@ -24,9 +24,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "rcunit_api.h"
-#include "testmoko.h"
-
+#include "rcunit_test.h"
static int nr_invocations = 0;
@@ -51,7 +49,6 @@ TMK_TEST(rcu_test_assert_single_evaluation) {
nr_invocations = 0;
RCU_ASSERT(return_1());
TMK_ASSERT_EQUAL(1, nr_invocations);
-
nr_invocations = 0;
RCU_ASSERT_TRUE(return_1());
TMK_ASSERT_EQUAL(1, nr_invocations);
@@ -63,19 +60,18 @@ TMK_TEST(rcu_test_assert_single_evaluation) {
nr_invocations = 0;
RCU_ASSERT_EQUAL(1, return_1());
TMK_ASSERT_EQUAL(1, nr_invocations);
-
+
nr_invocations = 0;
RCU_ASSERT_EQUAL_STRING("string", return_string());
TMK_ASSERT_EQUAL(1, nr_invocations);
-
+
nr_invocations = 0;
RCU_ASSERT_NULL(return_null_ptr());
TMK_ASSERT_EQUAL(1, nr_invocations);
nr_invocations = 0;
RCU_ASSERT_NOT_NULL(return_string());
TMK_ASSERT_EQUAL(1, nr_invocations);
-
}
RCU_TEST(rcu_bit_assertion_tests){
@@ -129,7 +125,32 @@ RCU_TEST(rcu_byte_assertion_tests){
RCU_ASSERT_NOT_SAME_BYTE_ARRAY(expected, actual, 4);
}
-TMK_TEST(rcu_test_byte_array_assertions) {
+TMK_TEST(rcu_test_byte_assertions) {
rcu_add_test(rcu_byte_assertion_tests);
TMK_ASSERT_EQUAL(RCU_E_OK, rcu_run_tests());
}
+
+RCU_TEST(rcu_float_assertion_tests) {
+ RCU_ASSERT_EQUAL_FLOATS(1.00001, 1.00001);
+ RCU_ASSERT_NOT_EQUAL_FLOATS(1.00001, 1.00000);
+}
+
+TMK_TEST(rcu_test_float_assertions) {
+ rcu_add_test(rcu_float_assertion_tests);
+ TMK_ASSERT_EQUAL(RCU_E_OK, rcu_run_tests());
+}
+
+RCU_TEST(rcu_pointer_assertion_tests) {
+ int x;
+ int *y = &x;
+ RCU_ASSERT_EQUAL_PTRS(&x, y);
+}
+
+TMK_TEST(rcu_test_pointer_assertions) {
+ rcu_add_test(rcu_pointer_assertion_tests);
+ TMK_ASSERT_EQUAL(RCU_E_OK, rcu_run_tests());
+}
+
+
+
+
@@ -24,7 +24,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "rcunit.h"
+#include "rcunit_test.h"
int rcu_test_exception_001_1() {
TMK_LOG("rcu_test_exception_001_1 invoked!");
@@ -24,10 +24,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include <testmoko.h>
-#include "rcunit.h"
-
-#include "rcunit_api.h"
+#include "rcunit_test.h"
extern void test(void *param);
extern void setup(void *param);
@@ -24,8 +24,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "rcunit.h"
-#include "testmoko.h"
+#include "rcunit_test.h"
/* Verify that we can create a test module */
TMK_TEST(rcu_test_get_mod) {
@@ -1,4 +1,4 @@
-#include "rcunit.h"
+#include "rcunit_test.h"
#define NR_ALLOCS 16
View
@@ -78,40 +78,55 @@ typedef struct tmk_test_function_entry {
* to this is to assign/evaluate it to a local variable (block scope)
*/
-/** @brief Asserts a condition */
+
+/* Asserts a condition */
#define TMK_ASSERT(cond) \
{ tmk_assert_impl((cond), __FILE__, __func__, __LINE__, "%s", #cond); }
-/** @brief Asserts a false condition */
+/* Asserts a false condition */
#define TMK_ASSERT_TRUE(cond) \
{ tmk_assert_impl((cond), __FILE__,__func__, __LINE__, "%s is not true", #cond); }
-/** @brief Asserts a false condition */
+/* Asserts a false condition */
#define TMK_ASSERT_FALSE(cond) \
{ tmk_assert_impl(!(cond), __FILE__,__func__,__LINE__, "%s is true", #cond); }
-/** @brief Asserts a null pointer */
+/* Asserts a null pointer */
#define TMK_ASSERT_NULL(ptr) \
{ tmk_assert_impl(((ptr) == NULL), __FILE__,__func__,__LINE__, "null"); }
-/** @brief Asserts a non-null pointer */
+/* Asserts a non-null pointer */
#define TMK_ASSERT_NOT_NULL(ptr) \
{ tmk_assert_impl(((ptr) != NULL), __FILE__,__func__,__LINE__,"pointer is not null"); }
-/** @brief Asserts that the two variables are equal */
+/* Asserts that the two variables are equal */
#define TMK_ASSERT_EQUAL(expected, actual) \
- { int __expected = expected; int __actual = actual; \
+ { long __expected = (long)expected; long __actual = (long)actual; \
tmk_assert_impl((__expected == __actual), __FILE__, __func__, __LINE__, \
"%s expected to be %d but got %d", #actual,__expected, __actual); \
}
-/** @brief Asserts that the two strings are equal */
+/* Asserts that the two floating points are equal */
+#define TMK_ASSERT_EQUAL_FLOATS(expected, actual) \
+ { double __expected = (double)expected; double __actual = (double)actual; \
+ tmk_assert_impl((__expected == __actual), __FILE__, __func__, __LINE__, \
+ "%s expected to be %lf but got %lf", #actual,__expected, __actual); \
+ }
+
+/* Asserts that the two pointers are equal */
+#define TMK_ASSERT_EQUAL_PTRS(expected, actual) \
+ { void *__expected = (void*)expected; void *__actual = (void*)actual; \
+ tmk_assert_impl((__expected == __actual), __FILE__, __func__, __LINE__, \
+ "%s expected to be %p but got %", #actual,__expected, __actual); \
+ }
+
+/* Asserts that the two strings are equal */
#define TMK_ASSERT_EQUAL_STRING(expected, actual) \
{ const char *__expected = expected; const char *__actual = actual; \
tmk_assert_impl( !(strcmp((__expected), (__actual))), __FILE__, __func__, __LINE__, \
"expected \"%s\" but got \"%s\"", __expected, __actual); }
-/** @brief Records an explicitly failed condition described by msg */
+/* Records an explicitly failed condition described by msg */
#define TMK_FAIL(msg) \
{ tmk_assert_impl(0, __FILE__, __func__, __LINE__, "Failed explicitly : %s", msg); }
@@ -128,7 +143,8 @@ void tmk_log_impl(const char* filename, const int line_no,
extern TMK_API int tmk_run_tests(const tmk_test_function_entry *tbl,
TMK_NULLABLE void (*setup)(), void (*teardown)());
-void tmk_assert_impl(int cond, const char *fname, const char *func_name, int line, const char *format, ...);
+extern void tmk_assert_impl(int cond, const char *filename, const char *func_name,int line, const char *format, ...);
+
#endif /* TESTMOKO_H */
Oops, something went wrong.

0 comments on commit 5cd7c5f

Please sign in to comment.