You can subscribe to this list here.
| 2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(23) |
Aug
(17) |
Sep
(4) |
Oct
(4) |
Nov
(7) |
Dec
(19) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2009 |
Jan
(5) |
Feb
|
Mar
(9) |
Apr
|
May
(14) |
Jun
(7) |
Jul
(6) |
Aug
(4) |
Sep
(7) |
Oct
(2) |
Nov
|
Dec
(2) |
| 2010 |
Jan
|
Feb
(13) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
(1) |
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(5) |
Jun
(1) |
Jul
(3) |
Aug
(2) |
Sep
(5) |
Oct
|
Nov
|
Dec
|
| 2012 |
Jan
(13) |
Feb
|
Mar
|
Apr
(6) |
May
(4) |
Jun
|
Jul
|
Aug
(19) |
Sep
(9) |
Oct
(2) |
Nov
(23) |
Dec
(23) |
| 2013 |
Jan
(18) |
Feb
(5) |
Mar
(11) |
Apr
(12) |
May
(5) |
Jun
(6) |
Jul
|
Aug
(2) |
Sep
(4) |
Oct
|
Nov
(5) |
Dec
(3) |
| 2014 |
Jan
|
Feb
|
Mar
|
Apr
(9) |
May
(5) |
Jun
|
Jul
(4) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
| 2016 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <th...@us...> - 2016-01-19 17:12:21
|
Revision: 562
http://sourceforge.net/p/cgreen/code/562
Author: thoni56
Date: 2016-01-19 17:12:14 +0000 (Tue, 19 Jan 2016)
Log Message:
-----------
Modified Paths:
--------------
trunk/cgreen/README
Modified: trunk/cgreen/README
===================================================================
--- trunk/cgreen/README 2014-12-27 23:18:13 UTC (rev 561)
+++ trunk/cgreen/README 2016-01-19 17:12:14 UTC (rev 562)
@@ -1,5 +1,16 @@
Cgreen
======
+
+Cgreen has moved to GitHub: https://github.com/cgreen-devs/cgreen
+
+Go there to find latest source code, enter issues and follow development!
+
+
+
+
+The old README follows...
+
+
You probably got this package from...
http://cgreen.sourceforge.net/projects/cgreen/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <th...@us...> - 2014-08-07 16:29:14
|
Revision: 559
http://sourceforge.net/p/cgreen/code/559
Author: thoni56
Date: 2014-08-07 16:28:54 +0000 (Thu, 07 Aug 2014)
Log Message:
-----------
Added setting of POLICY for @rpath on Darwin and cmake >= 3.0
Modified Paths:
--------------
trunk/cgreen/CMakeLists.txt
Modified: trunk/cgreen/CMakeLists.txt
===================================================================
--- trunk/cgreen/CMakeLists.txt 2014-08-01 13:27:58 UTC (rev 558)
+++ trunk/cgreen/CMakeLists.txt 2014-08-07 16:28:54 UTC (rev 559)
@@ -2,6 +2,11 @@
cmake_minimum_required(VERSION 2.6)
set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required
+if (NOT(CMAKE_MAJOR_VERSION LESS 3) AND APPLE)
+ if(POLICY CMP0042)
+ cmake_policy(SET CMP0042 NEW) # CMake 3.0 to use @rpath on MacOSX libraries
+ endif()
+endif()
project(cgreen C)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <th...@us...> - 2014-08-01 13:28:05
|
Revision: 558
http://sourceforge.net/p/cgreen/code/558
Author: thoni56
Date: 2014-08-01 13:27:58 +0000 (Fri, 01 Aug 2014)
Log Message:
-----------
Don't need source for old website anymore
Removed Paths:
-------------
trunk/cgreen/doc/images/
trunk/cgreen/doc/source/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <th...@us...> - 2014-07-24 08:30:02
|
Revision: 557
http://sourceforge.net/p/cgreen/code/557
Author: thoni56
Date: 2014-07-24 08:29:52 +0000 (Thu, 24 Jul 2014)
Log Message:
-----------
Added patch for STATIC_LIBRARY on Linux from Chris LeBlanc
Modified Paths:
--------------
trunk/cgreen/src/CMakeLists.txt
Modified: trunk/cgreen/src/CMakeLists.txt
===================================================================
--- trunk/cgreen/src/CMakeLists.txt 2014-07-24 08:03:21 UTC (rev 556)
+++ trunk/cgreen/src/CMakeLists.txt 2014-07-24 08:29:52 UTC (rev 557)
@@ -135,9 +135,15 @@
add_library(${CGREEN_STATIC_LIBRARY} STATIC ${cgreen_SRCS})
-target_link_libraries(${CGREEN_STATIC_LIBRARY}
+if (WITH_CXX)
+ target_link_libraries(${CGREEN_STATIC_LIBRARY}
+ ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}
+ )
+endif (WITH_CXX)
+
+target_link_libraries(${CGREEN_STATIC_LIBRARY}
${CGREEN_LINK_LIBRARIES}
- ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}
+ ${MATH_LIB}
)
set_target_properties(
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <th...@us...> - 2014-07-24 08:03:41
|
Revision: 556
http://sourceforge.net/p/cgreen/code/556
Author: thoni56
Date: 2014-07-24 08:03:21 +0000 (Thu, 24 Jul 2014)
Log Message:
-----------
Applied patch for a few memory leaks from Dirk Jagdmann
Modified Paths:
--------------
trunk/cgreen/tools/cgreen-runner.c
trunk/cgreen/tools/runner.c
trunk/cgreen/tools/tests/runnerTests.c
Modified: trunk/cgreen/tools/cgreen-runner.c
===================================================================
--- trunk/cgreen/tools/cgreen-runner.c 2014-07-24 07:40:45 UTC (rev 555)
+++ trunk/cgreen/tools/cgreen-runner.c 2014-07-24 08:03:21 UTC (rev 556)
@@ -12,6 +12,7 @@
/*----------------------------------------------------------------------*/
static int file_exists(const char *filename)
{
+ if (! filename) return 0;
return (access(filename, F_OK) == 0);
}
@@ -44,15 +45,21 @@
if (options) free(options);
}
-static const char *get_a_suite_name(const char *suite_option, const char *test_library_name) {
- const char *suite_name;
+static char* get_a_suite_name(const char *suite_option, const char *test_library_name) {
if (suite_option == NULL) {
- suite_name = basename(strdup(test_library_name));
- if (strchr(suite_name, '.'))
- *strchr(suite_name, '.') = '\0';
+ char *suite_name;
+ char *s;
+ /* basename can return the parameter or an internal static string. Work around this. */
+ s = strdup(test_library_name);
+ suite_name = strdup(basename(s));
+ free(s);
+ if ((s = strchr(suite_name, '.'))) {
+ *s = '\0';
+ }
return suite_name;
- } else
- return suite_option;
+ } else {
+ return strdup(suite_option);
+ }
}
@@ -158,9 +165,11 @@
status = runner(reporter, test_library, suite_name, test_name, verbose, no_run);
if (status != 0) {
- printf("Library %s resulted in error status: %i\n", test_library, status);
+ printf("Library %s with test %s/%s resulted in error status: %i\n", test_library, suite_name, test_name, status);
return status;
}
+
+ free((void*)suite_name);
}
return EXIT_SUCCESS;
Modified: trunk/cgreen/tools/runner.c
===================================================================
--- trunk/cgreen/tools/runner.c 2014-07-24 07:40:45 UTC (rev 555)
+++ trunk/cgreen/tools/runner.c 2014-07-24 08:03:21 UTC (rev 556)
@@ -334,6 +334,7 @@
printf("Discovered %s:%s (%s)\n", suite_name, test_name, function_name);
free(suite_name);
free(test_name);
+ free(function_name);
}
if (register_test(test_items, maximum_number_of_test_items, specification_name) < 0) {
ret = -1;
Modified: trunk/cgreen/tools/tests/runnerTests.c
===================================================================
--- trunk/cgreen/tools/tests/runnerTests.c 2014-07-24 07:40:45 UTC (rev 555)
+++ trunk/cgreen/tools/tests/runnerTests.c 2014-07-24 08:03:21 UTC (rev 556)
@@ -21,8 +21,9 @@
Ensure(Runner, can_demangle_specification_to_function_name) {
// NOTE: Must have the test name duplicated in the assert to compare to the actual function name
- assert_that(function_name_from_specname(STRINGIFY(spec_name(Runner, can_demangle_specification_to_function_name))),
- is_equal_to_string(__FUNCTION__));
+ char *function_name = function_name_from_specname(STRINGIFY(spec_name(Runner, can_demangle_specification_to_function_name)));
+ assert_that(function_name, is_equal_to_string(__FUNCTION__));
+ free(function_name);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <th...@us...> - 2014-07-24 07:41:06
|
Revision: 555
http://sourceforge.net/p/cgreen/code/555
Author: thoni56
Date: 2014-07-24 07:40:45 +0000 (Thu, 24 Jul 2014)
Log Message:
-----------
Added an -O2 options if FORTIFY_SOURCE since some GCC versions requires it
Modified Paths:
--------------
trunk/cgreen/cmake/Modules/DefineCompilerFlags.cmake
Modified: trunk/cgreen/cmake/Modules/DefineCompilerFlags.cmake
===================================================================
--- trunk/cgreen/cmake/Modules/DefineCompilerFlags.cmake 2014-07-19 09:20:26 UTC (rev 554)
+++ trunk/cgreen/cmake/Modules/DefineCompilerFlags.cmake 2014-07-24 07:40:45 UTC (rev 555)
@@ -56,7 +56,7 @@
check_c_compiler_flag("-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
if (WITH_FORTIFY_SOURCE)
- add_definitions(-D_FORTIFY_SOURCE=2)
+ add_definitions(-D_FORTIFY_SOURCE=2 -O2)
endif (WITH_FORTIFY_SOURCE)
endif (CMAKE_COMPILER_IS_GNUCC OR COMPILER_IS_CLANG)
endif (UNIX)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <th...@us...> - 2014-07-19 09:20:35
|
Revision: 554
http://sourceforge.net/p/cgreen/code/554
Author: thoni56
Date: 2014-07-19 09:20:26 +0000 (Sat, 19 Jul 2014)
Log Message:
-----------
Changed erroneous "it's" to "its"
Modified Paths:
--------------
trunk/cgreen/doc/cgreen-guide-en.asciidoc
Modified: trunk/cgreen/doc/cgreen-guide-en.asciidoc
===================================================================
--- trunk/cgreen/doc/cgreen-guide-en.asciidoc 2014-05-06 07:20:24 UTC (rev 553)
+++ trunk/cgreen/doc/cgreen-guide-en.asciidoc 2014-07-19 09:20:26 UTC (rev 554)
@@ -27,7 +27,7 @@
- Fully composable test suites
- 'setup()' and 'teardown()' for tests and test suites
-- Each test runs in it's own process
+- Each test runs in its own process
- An isolated test can be run in a single process for debugging
- Ability to mock functions
- The reporting mechanism can be easily extended
@@ -965,7 +965,7 @@
}
--------------------------
-We have already factored out the duplicate code into it's own
+We have already factored out the duplicate code into its own
functions 'create_scheme()' and 'drop_schema()', so things are not so
bad. At least not yet. What happens when we get dozens of tests? For a
test subject as complicated as a database
@@ -1030,7 +1030,7 @@
the test crashes, causing some test interference. This brings us
nicely onto the next section...
-Each test in it's own process
+Each test in its own process
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider this test method...
@@ -1048,10 +1048,10 @@
you need to tackle the problem.
To prevent segmentation faults and other problems bringing down the
-test suites, *Cgreen* runs every test in it's own process.
+test suites, *Cgreen* runs every test in its own process.
Just before calling the 'setup' function, *Cgreen* 'fork()''s. The main
-process wait's for the test to complete normally or die. This includes
+process waits for the test to complete normally or die. This includes
the calling the 'teardown' function, if any. If the test process dies,
an exception is reported and the main test process carries on.
@@ -1217,7 +1217,7 @@
an optional argument. The entire test suite will be searched for the
named test. This trick also saves us a recompile when we debug.
-We've placed each test suite in it's own file, but that is not
+We've placed each test suite in its own file, but that is not
necessary. We could build several test suites in the same file, even
nesting them. We can even add mixtures of test functions and test
suites to the same parent test suite. Loops will give trouble,
@@ -1301,7 +1301,7 @@
still attached to the inner 'suite'.
In the real world we would probably place the connection
-fixture in it's own file...
+fixture in its own file...
[source,c]
-----------------------
@@ -1566,7 +1566,7 @@
}
-----------------------
-I've been a bit naughty. As each test runs in it's own process, I
+I've been a bit naughty. As each test runs in its own process, I
haven't bothered to free the pointers to the paragraphs. I've just
let the operating system do it. Purists may want to add the extra
clean up code.
@@ -1577,7 +1577,7 @@
'read_paragraph()' function could quite legitimately call the stream
after it had run off of the end. OK, that would be odd behaviour, but
that's not what we are testing here. If we were, it would be placed
-in a test of it's own. The 'always_expect()' call tells *Cgreen* to
+in a test of its own. The 'always_expect()' call tells *Cgreen* to
keep going after the first three letters, allowing extra calls.
As we build more and more tests, they start to look like a
@@ -1783,8 +1783,8 @@
Where are the assertions?
-Unlike our earlier stub, 'reader()' can now check it's parameters. In
-object oriented circles, an object that checks it's parameters as well
+Unlike our earlier stub, 'reader()' can now check its parameters. In
+object oriented circles, an object that checks its parameters as well
as simulating behaviour is called a mock object. By analogy
'reader()' is a mock function, or mock callback.
@@ -2623,7 +2623,7 @@
and 'reporter_finish()' functions is optional, I want to
make use of some of the facilities later.
-Our output meanwhile, is making it's first tentative steps...
+Our output meanwhile, is making its first tentative steps...
[source,xml]
-----------------------
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tho...@us...> - 2014-05-02 10:00:33
|
Revision: 552
http://sourceforge.net/p/cgreen/code/552
Author: thomasnilsson
Date: 2014-05-02 10:00:23 +0000 (Fri, 02 May 2014)
Log Message:
-----------
Ensured that CppConstraint uses the same compare field as the inherited compare (then actually the added field does not make any sense...)
Ensured that destroy_constraint() only calls the destroy if it exists (and, yes, that will leak a few bytes sometimes, but there seems to be no destroy_cpp_constraint() yet...)
So now C++ test suite also passes
Modified Paths:
--------------
trunk/cgreen/include/cgreen/cpp_constraint.h
trunk/cgreen/src/constraint.c
Modified: trunk/cgreen/include/cgreen/cpp_constraint.h
===================================================================
--- trunk/cgreen/include/cgreen/cpp_constraint.h 2014-05-01 20:48:41 UTC (rev 551)
+++ trunk/cgreen/include/cgreen/cpp_constraint.h 2014-05-02 10:00:23 UTC (rev 552)
@@ -45,7 +45,7 @@
constraint = new CppConstraint<T>();
constraint->type = VALUE_COMPARER;
- constraint->compare = &compare_want_value;
+ constraint->Constraint::compare = &compare_want_value;
constraint->execute = &test_want;
constraint->name = "equal";
constraint->expected_value = expected_value;
Modified: trunk/cgreen/src/constraint.c
===================================================================
--- trunk/cgreen/src/constraint.c 2014-05-01 20:48:41 UTC (rev 551)
+++ trunk/cgreen/src/constraint.c 2014-05-02 10:00:23 UTC (rev 552)
@@ -90,7 +90,8 @@
}
void destroy_constraint(Constraint *constraint) {
- (*constraint->destroy)(constraint);
+ if (constraint->destroy != NULL)
+ (*constraint->destroy)(constraint);
}
void destroy_constraints(va_list constraints) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tho...@us...> - 2014-05-01 20:48:50
|
Revision: 551
http://sourceforge.net/p/cgreen/code/551
Author: thomasnilsson
Date: 2014-05-01 20:48:41 +0000 (Thu, 01 May 2014)
Log Message:
-----------
Changed handling of blocked pipe so that the test case for it works
However it reveals a C++ problem with uninitialized CppConstaints
which fails the test suite for C++
Modified Paths:
--------------
trunk/cgreen/cmake/Modules/DefineCompilerFlags.cmake
trunk/cgreen/include/cgreen/cpp_constraint.h
trunk/cgreen/src/posix_cgreen_pipe.c
Modified: trunk/cgreen/cmake/Modules/DefineCompilerFlags.cmake
===================================================================
--- trunk/cgreen/cmake/Modules/DefineCompilerFlags.cmake 2014-05-01 13:28:45 UTC (rev 550)
+++ trunk/cgreen/cmake/Modules/DefineCompilerFlags.cmake 2014-05-01 20:48:41 UTC (rev 551)
@@ -11,7 +11,7 @@
if (UNIX)
if (CMAKE_COMPILER_IS_GNUCC OR COMPILER_IS_CLANG)
if (WITH_CXX)
- add_definitions( -g -Weffc++ -Wall -Wextra -Wunused)
+ add_definitions(-g -Weffc++ -Wall -Wextra -Wunused)
else()
add_definitions(-g -std=c99 -Wall -Wextra -Wunused)
endif (WITH_CXX)
Modified: trunk/cgreen/include/cgreen/cpp_constraint.h
===================================================================
--- trunk/cgreen/include/cgreen/cpp_constraint.h 2014-05-01 13:28:45 UTC (rev 550)
+++ trunk/cgreen/include/cgreen/cpp_constraint.h 2014-05-01 20:48:41 UTC (rev 551)
@@ -37,10 +37,12 @@
void test_want_value(CppConstraint<T> *constraint, const char *function, T actual, const char *test_file, int test_line, TestReporter *reporter) {
}
+#include <stdlib.h>
// TODO: add create_equal_to_constraint_<T> where operator<< output is used for expected_value name
template<typename T>
CppConstraint<T> *create_equal_to_value_constraint(T expected_value, const char *expected_value_name) {
CppConstraint<T> *constraint;// = create_cpp_constraint<T>();
+ constraint = new CppConstraint<T>();
constraint->type = VALUE_COMPARER;
constraint->compare = &compare_want_value;
Modified: trunk/cgreen/src/posix_cgreen_pipe.c
===================================================================
--- trunk/cgreen/src/posix_cgreen_pipe.c 2014-05-01 13:28:45 UTC (rev 550)
+++ trunk/cgreen/src/posix_cgreen_pipe.c 2014-05-01 20:48:41 UTC (rev 551)
@@ -4,6 +4,7 @@
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
+#include <sys/wait.h>
#ifndef O_ASYNC
# define O_ASYNC FASYNC
@@ -55,19 +56,18 @@
ssize_t cgreen_pipe_write(int p, const void *buf, size_t count)
{
int pipe_write_result = write(p, buf, count);
+ int status;
if (pipe_write_result < 0) {
if (errno == EWOULDBLOCK) {
fprintf(stderr, "\tCGREEN EXCEPTION: Too many assertions within a single test.\n");
} else if (errno != EPIPE) {
fprintf(stderr, "\tCGREEN EXCEPTION: Error when reporting from test case process to reporter\n");
}
- kill(getpid(), SIGPIPE);
raise(SIGPIPE);
+ wait(&status); /* Safe-guarding against a signalhandler for SIGPIPE, which
+ incidentaly the test case for pipe block need to have... */
}
-
- return write(p, buf, count);
-
- // return pipe_write_result;
+ return pipe_write_result;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tho...@us...> - 2014-05-01 13:28:53
|
Revision: 550
http://sourceforge.net/p/cgreen/code/550
Author: thomasnilsson
Date: 2014-05-01 13:28:45 +0000 (Thu, 01 May 2014)
Log Message:
-----------
Also forgot a debug printout
Modified Paths:
--------------
trunk/cgreen/tests/messaging_tests.c
Modified: trunk/cgreen/tests/messaging_tests.c
===================================================================
--- trunk/cgreen/tests/messaging_tests.c 2014-05-01 13:16:01 UTC (rev 549)
+++ trunk/cgreen/tests/messaging_tests.c 2014-05-01 13:28:45 UTC (rev 550)
@@ -34,7 +34,6 @@
static int signal_received = 0;
static void catch_signal(int s) {
(void)s;
- fprintf(stderr, "CAUGHT"); fflush(NULL);
signal_received = 1;
signal(SIGPIPE, SIG_DFL);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tho...@us...> - 2014-05-01 13:16:10
|
Revision: 549
http://sourceforge.net/p/cgreen/code/549
Author: thomasnilsson
Date: 2014-05-01 13:16:01 +0000 (Thu, 01 May 2014)
Log Message:
-----------
How could I miss the include...
Modified Paths:
--------------
trunk/cgreen/tests/messaging_tests.c
Modified: trunk/cgreen/tests/messaging_tests.c
===================================================================
--- trunk/cgreen/tests/messaging_tests.c 2014-05-01 13:02:30 UTC (rev 548)
+++ trunk/cgreen/tests/messaging_tests.c 2014-05-01 13:16:01 UTC (rev 549)
@@ -3,6 +3,8 @@
#include <stdlib.h>
#include <stdio.h>
+#include <signal.h>
+
#ifdef __cplusplus
using namespace cgreen;
#endif
@@ -31,6 +33,7 @@
static int signal_received = 0;
static void catch_signal(int s) {
+ (void)s;
fprintf(stderr, "CAUGHT"); fflush(NULL);
signal_received = 1;
signal(SIGPIPE, SIG_DFL);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tho...@us...> - 2014-05-01 13:02:39
|
Revision: 548
http://sourceforge.net/p/cgreen/code/548
Author: thomasnilsson
Date: 2014-05-01 13:02:30 +0000 (Thu, 01 May 2014)
Log Message:
-----------
Modified handling of the pipe becoming full. Now an exception is also generated.
Fixed a presumable error in that cgreen_pipe_write() wrote the message twice.
Modified Paths:
--------------
trunk/cgreen/src/posix_cgreen_pipe.c
trunk/cgreen/tests/messaging_tests.c
Modified: trunk/cgreen/src/posix_cgreen_pipe.c
===================================================================
--- trunk/cgreen/src/posix_cgreen_pipe.c 2014-04-12 08:45:59 UTC (rev 547)
+++ trunk/cgreen/src/posix_cgreen_pipe.c 2014-05-01 13:02:30 UTC (rev 548)
@@ -56,16 +56,18 @@
{
int pipe_write_result = write(p, buf, count);
if (pipe_write_result < 0) {
- if (errno == EWOULDBLOCK) {
- fprintf(stderr, "\tToo many assertions (> 8192) within a single test.\n");
+ if (errno == EWOULDBLOCK) {
+ fprintf(stderr, "\tCGREEN EXCEPTION: Too many assertions within a single test.\n");
} else if (errno != EPIPE) {
- fprintf(stderr, "\tError reporting from test case process to reporter\n");
+ fprintf(stderr, "\tCGREEN EXCEPTION: Error when reporting from test case process to reporter\n");
}
-
kill(getpid(), SIGPIPE);
+ raise(SIGPIPE);
}
- return write(p,buf,count);
+ return write(p, buf, count);
+
+ // return pipe_write_result;
}
Modified: trunk/cgreen/tests/messaging_tests.c
===================================================================
--- trunk/cgreen/tests/messaging_tests.c 2014-04-12 08:45:59 UTC (rev 547)
+++ trunk/cgreen/tests/messaging_tests.c 2014-05-01 13:02:30 UTC (rev 548)
@@ -29,14 +29,28 @@
assert_equal(receive_cgreen_message(messaging), 99);
}
-Ensure(failure_reported_when_messaging_would_block) {
+static int signal_received = 0;
+static void catch_signal(int s) {
+ fprintf(stderr, "CAUGHT"); fflush(NULL);
+ signal_received = 1;
+ signal(SIGPIPE, SIG_DFL);
+}
+
+Ensure(failure_reported_and_exception_thrown_when_messaging_would_block) {
+ const int LOOPS = 65536;
int messaging = start_cgreen_messaging(33);
int loop;
- for (loop = 0; loop < 65536; loop++) {
+
+ signal_received = 0;
+ signal(SIGPIPE, catch_signal);
+ for (loop = 0; loop < LOOPS; loop++) {
send_cgreen_message(messaging, 99);
+ if (signal_received == 1)
+ break;
}
- fail_test("This test should be killed due to too many messages before it gets here");
+ assert_that(signal_received, is_equal_to(1));
+ assert_that(loop, is_less_than(LOOPS));
}
TestSuite *messaging_tests() {
@@ -44,7 +58,7 @@
add_suite(suite, highly_nested_test_suite());
add_test(suite, can_send_message);
#ifndef WIN32 // TODO: win32 needs non-blocking pipes like posix for this to pass
- add_test(suite, failure_reported_when_messaging_would_block);
+ add_test(suite, failure_reported_and_exception_thrown_when_messaging_would_block);
#endif
return suite;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tho...@us...> - 2014-04-12 08:46:07
|
Revision: 547
http://sourceforge.net/p/cgreen/code/547
Author: thomasnilsson
Date: 2014-04-12 08:45:59 +0000 (Sat, 12 Apr 2014)
Log Message:
-----------
Added a first attempt at a setup script for Cygwin development (since Cygwin is a DLL platform it uses Windows procedure for locating DLLs this bites us every time, the build directories must be a head of any installed versions in the PATH)
Added Paths:
-----------
trunk/cgreen/cygwin-setup.sh
Added: trunk/cgreen/cygwin-setup.sh
===================================================================
--- trunk/cgreen/cygwin-setup.sh (rev 0)
+++ trunk/cgreen/cygwin-setup.sh 2014-04-12 08:45:59 UTC (rev 547)
@@ -0,0 +1,29 @@
+#! /bin/sh
+#
+# I'm making some notes here for future reference: CYGWIN is *not*
+# WIN32, but it *is* a DLL-platform So it loads DLL:s the same way
+# Windows does, namely from the path. That means that for tests to run
+# using the freshly build DLL:s in the build tree both include paths
+# but also the PATH need to be prepended by the directory of the
+# DLL. This could be done with something like:
+#
+# set_tests_properties(SomeTest PROPERTIES ENVIRONMENT "PATH=c:\somedir;c:\otherdir")
+#
+# which I found at http://stackoverflow.com/a/1079072/204658. The
+# thing to work out is what CMAKE variables point to that
+# directory. The follwing should be evolved to do just that, so that a
+# CYGWIN developer could just source this script and then forget about
+# it.
+#
+
+# The following is a first (non-successful) attempt at ensuring that
+# the script is sourced:
+if [[ $_ != $0 ]]; then
+ echo "Sourced"
+else
+ echo "Subshell"
+fi
+
+# And here's the meat
+export PATH="$PWD/build/build-c/src":"$PWD/build/build-c++/src":$PATH
+export PATH="$PWD/build/build-c/tools":"$PWD/build/build-c++/tools":$PATH
Property changes on: trunk/cgreen/cygwin-setup.sh
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tho...@us...> - 2014-04-10 12:20:10
|
Revision: 546
http://sourceforge.net/p/cgreen/code/546
Author: thomasnilsson
Date: 2014-04-10 12:20:01 +0000 (Thu, 10 Apr 2014)
Log Message:
-----------
Minor formatting adjustment to ensure that a single empty line is printed after assertion errors regardless of combinations of presence of expected and actual values
Modified Paths:
--------------
trunk/cgreen/src/message_formatting.c
Modified: trunk/cgreen/src/message_formatting.c
===================================================================
--- trunk/cgreen/src/message_formatting.c 2014-04-08 06:41:22 UTC (rev 545)
+++ trunk/cgreen/src/message_formatting.c 2014-04-10 12:20:01 UTC (rev 546)
@@ -117,9 +117,9 @@
char actual_value_string[32];
const char *actual_value_constraint_name = "Expected [%s] to [%s]";
const char *expected_value_name = "[%s]\n";
- const char *actual_value_as_string = "\t\tactual value:\t\t\t[\"%s\"]\n";
+ const char *actual_value_as_string = "\t\tactual value:\t\t\t[\"%s\"]";
const char *at_offset = "\t\tat offset:\t\t\t[%d]";
- const char *actual_value_message = "\t\tactual value:\t\t\t[%" PRIdPTR "]\n";
+ const char *actual_value_message = "\t\tactual value:\t\t\t[%" PRIdPTR "]";
char *message;
size_t message_size = strlen(actual_value_constraint_name) +
strlen(expected_value_name) +
@@ -170,6 +170,7 @@
actual_value_as_string,
(const char *)actual);
if (strstr(constraint->name, "not ") == NULL || strstr(constraint->name, "contain ") != NULL) {
+ strcat(message, "\n");
snprintf(message + strlen(message), message_size - strlen(message) - 1,
constraint->expected_value_message,
(const char *)constraint->expected_value);
@@ -191,6 +192,7 @@
actual);
if (strstr(constraint->name, "not ") == NULL) {
+ strcat(message, "\n");
snprintf(message + strlen(message), message_size - strlen(message) - 1,
constraint->expected_value_message,
constraint->expected_value);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tho...@us...> - 2014-04-08 06:41:29
|
Revision: 545
http://sourceforge.net/p/cgreen/code/545
Author: thomasnilsson
Date: 2014-04-08 06:41:22 +0000 (Tue, 08 Apr 2014)
Log Message:
-----------
Fixed a compilation problem on MacOSX (native lcc)
Modified Paths:
--------------
trunk/cgreen/include/cgreen/cpp_constraint.h
Modified: trunk/cgreen/include/cgreen/cpp_constraint.h
===================================================================
--- trunk/cgreen/include/cgreen/cpp_constraint.h 2014-04-07 04:41:55 UTC (rev 544)
+++ trunk/cgreen/include/cgreen/cpp_constraint.h 2014-04-08 06:41:22 UTC (rev 545)
@@ -9,8 +9,9 @@
template<typename T>
class CppConstraint : public Constraint {
- T expected_real_value;
- bool (*compare)(CppConstraint *, T);
+ public:
+ T expected_real_value;
+ bool (*compare)(CppConstraint *, T);
};
Constraint *create_equal_to_string_constraint(const std::string& expected_value, const char *expected_value_name);
@@ -48,7 +49,7 @@
constraint->expected_value = expected_value;
constraint->expected_value_name = expected_value_name;
constraint->size_of_expected_value = sizeof(intptr_t);
- constraint->real_expected_value = expected_value;
+ constraint->expected_real_value = expected_value;
return constraint;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2014-04-07 04:42:04
|
Revision: 544
http://sourceforge.net/p/cgreen/code/544
Author: matt_hargett
Date: 2014-04-07 04:41:55 +0000 (Mon, 07 Apr 2014)
Log Message:
-----------
fix regression when running test_all_constraints suite without the cgreen-runner.
Modified Paths:
--------------
trunk/cgreen/src/posix_cgreen_pipe.c
Modified: trunk/cgreen/src/posix_cgreen_pipe.c
===================================================================
--- trunk/cgreen/src/posix_cgreen_pipe.c 2014-04-07 04:05:43 UTC (rev 543)
+++ trunk/cgreen/src/posix_cgreen_pipe.c 2014-04-07 04:41:55 UTC (rev 544)
@@ -44,7 +44,7 @@
ssize_t cgreen_pipe_read(int p, void *buf, size_t count)
{
- if (0 != fcntl(p, F_SETFL, O_ASYNC)) {
+ if (0 != fcntl(p, F_SETFL, O_NONBLOCK)) {
fprintf(stderr, "could not set file status flag on read pipe\n");
return -1;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2014-04-07 04:05:51
|
Revision: 543
http://sourceforge.net/p/cgreen/code/543
Author: matt_hargett
Date: 2014-04-07 04:05:43 +0000 (Mon, 07 Apr 2014)
Log Message:
-----------
apply patch 27 from the tracker with minor changes. thanks to Steven Lang.
Modified Paths:
--------------
trunk/cgreen/src/posix_cgreen_pipe.c
trunk/cgreen/tests/messaging_tests.c
Modified: trunk/cgreen/src/posix_cgreen_pipe.c
===================================================================
--- trunk/cgreen/src/posix_cgreen_pipe.c 2014-04-07 02:30:25 UTC (rev 542)
+++ trunk/cgreen/src/posix_cgreen_pipe.c 2014-04-07 04:05:43 UTC (rev 543)
@@ -1,7 +1,9 @@
#include "cgreen/internal/cgreen_pipe.h"
+#include <errno.h>
#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
#include <unistd.h>
-#include <stdio.h>
#ifndef O_ASYNC
# define O_ASYNC FASYNC
@@ -17,7 +19,22 @@
int cgreen_pipe_open(int pipes[2])
{
- return pipe(pipes);
+ int pipe_open_result;
+ int pipe_nonblock_result;
+
+ pipe_open_result = pipe(pipes);
+
+ if (pipe_open_result != 0) {
+ return pipe_open_result;
+ }
+
+ pipe_nonblock_result = fcntl(pipes[1], F_SETFL, O_NONBLOCK);
+
+ if (pipe_nonblock_result != 0) {
+ return pipe_open_result;
+ }
+
+ return 0;
}
void cgreen_pipe_close(int p)
@@ -32,11 +49,22 @@
return -1;
}
- return read(p,buf,count);
+ return read(p, buf, count);
}
ssize_t cgreen_pipe_write(int p, const void *buf, size_t count)
{
+ int pipe_write_result = write(p, buf, count);
+ if (pipe_write_result < 0) {
+ if (errno == EWOULDBLOCK) {
+ fprintf(stderr, "\tToo many assertions (> 8192) within a single test.\n");
+ } else if (errno != EPIPE) {
+ fprintf(stderr, "\tError reporting from test case process to reporter\n");
+ }
+
+ kill(getpid(), SIGPIPE);
+ }
+
return write(p,buf,count);
}
Modified: trunk/cgreen/tests/messaging_tests.c
===================================================================
--- trunk/cgreen/tests/messaging_tests.c 2014-04-07 02:30:25 UTC (rev 542)
+++ trunk/cgreen/tests/messaging_tests.c 2014-04-07 04:05:43 UTC (rev 543)
@@ -29,9 +29,22 @@
assert_equal(receive_cgreen_message(messaging), 99);
}
+Ensure(failure_reported_when_messaging_would_block) {
+ int messaging = start_cgreen_messaging(33);
+ int loop;
+ for (loop = 0; loop < 65536; loop++) {
+ send_cgreen_message(messaging, 99);
+ }
+
+ fail_test("This test should be killed due to too many messages before it gets here");
+}
+
TestSuite *messaging_tests() {
TestSuite *suite = create_test_suite();
add_suite(suite, highly_nested_test_suite());
add_test(suite, can_send_message);
+#ifndef WIN32 // TODO: win32 needs non-blocking pipes like posix for this to pass
+ add_test(suite, failure_reported_when_messaging_would_block);
+#endif
return suite;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2014-04-07 02:30:35
|
Revision: 542
http://sourceforge.net/p/cgreen/code/542
Author: matt_hargett
Date: 2014-04-07 02:30:25 +0000 (Mon, 07 Apr 2014)
Log Message:
-----------
apply a modified version of patch #26 from the sourceforge tracker. thanks to Ethan Barnes!
Modified Paths:
--------------
trunk/cgreen/include/cgreen/internal/suite_internal.h
trunk/cgreen/include/cgreen/internal/unit_implementation.h
trunk/cgreen/include/cgreen/suite.h
trunk/cgreen/src/messaging.c
trunk/cgreen/src/mocks.c
trunk/cgreen/src/posix_runner_platform.c
Modified: trunk/cgreen/include/cgreen/internal/suite_internal.h
===================================================================
--- trunk/cgreen/include/cgreen/internal/suite_internal.h 2014-04-06 22:19:30 UTC (rev 541)
+++ trunk/cgreen/include/cgreen/internal/suite_internal.h 2014-04-07 02:30:25 UTC (rev 542)
@@ -27,8 +27,8 @@
const char* filename;
int line;
UnitTest *tests;
- void (*setup)();
- void (*teardown)();
+ void (*setup)(void);
+ void (*teardown)(void);
int size;
};
Modified: trunk/cgreen/include/cgreen/internal/unit_implementation.h
===================================================================
--- trunk/cgreen/include/cgreen/internal/unit_implementation.h 2014-04-06 22:19:30 UTC (rev 541)
+++ trunk/cgreen/include/cgreen/internal/unit_implementation.h 2014-04-07 02:30:25 UTC (rev 542)
@@ -38,14 +38,14 @@
#define EnsureWithContextAndSpecificationName(contextName, spec, ...) \
static void contextName##__##spec (void);\
CgreenTest spec_name(contextName, spec) = { &contextFor##contextName, #spec, &contextName##__##spec, __FILE__, __LINE__ };\
- static void contextName##__##spec ()
+ static void contextName##__##spec (void)
extern CgreenContext defaultContext;
#define EnsureWithSpecificationName(spec, ...) \
static void spec (void);\
CgreenTest spec_name(default, spec) = { &defaultContext, #spec, &spec, __FILE__, __LINE__ };\
- static void spec ()
+ static void spec (void)
#define DescribeImplementation(subject) \
static void setup(void); \
Modified: trunk/cgreen/include/cgreen/suite.h
===================================================================
--- trunk/cgreen/include/cgreen/suite.h 2014-04-06 22:19:30 UTC (rev 541)
+++ trunk/cgreen/include/cgreen/suite.h 2014-04-07 02:30:25 UTC (rev 542)
@@ -23,8 +23,8 @@
#define add_tests(suite, ...) add_tests_(suite, #__VA_ARGS__, (CgreenTest *)__VA_ARGS__)
#define add_suite(owner, suite) add_suite_(owner, #suite, suite)
-void set_setup(TestSuite *suite, void (*set_up)());
-void set_teardown(TestSuite *suite, void (*tear_down)());
+void set_setup(TestSuite *suite, void (*set_up)(void));
+void set_teardown(TestSuite *suite, void (*tear_down)(void));
int count_tests(TestSuite *suite);
bool has_test(TestSuite *suite, const char *name);
bool has_setup(TestSuite *suite);
Modified: trunk/cgreen/src/messaging.c
===================================================================
--- trunk/cgreen/src/messaging.c 2014-04-06 22:19:30 UTC (rev 541)
+++ trunk/cgreen/src/messaging.c 2014-04-07 02:30:25 UTC (rev 542)
@@ -36,7 +36,7 @@
static CgreenMessageQueue *queues = NULL;
static int queue_count = 0;
-int get_pipe_read_handle()
+int get_pipe_read_handle(void)
{
if (queue_count)
{
@@ -46,7 +46,7 @@
return 0;
}
-int get_pipe_write_handle()
+int get_pipe_write_handle(void)
{
if (queue_count)
{
@@ -127,7 +127,7 @@
return result;
}
-static void clean_up_messaging() {
+static void clean_up_messaging(void) {
int i;
for (i = 0; i < queue_count; i++) {
if (queues[i].owner == getpid()) {
Modified: trunk/cgreen/src/mocks.c
===================================================================
--- trunk/cgreen/src/mocks.c 2014-04-06 22:19:30 UTC (rev 541)
+++ trunk/cgreen/src/mocks.c 2014-04-07 02:30:25 UTC (rev 542)
@@ -415,7 +415,7 @@
expectation->function);
}
-void clear_mocks() {
+void clear_mocks(void) {
if (global_expectation_queue != NULL) {
destroy_cgreen_vector(global_expectation_queue);
global_expectation_queue = NULL;
@@ -505,21 +505,21 @@
free(expectation);
}
-static void ensure_successfully_mocked_calls_list_exists() {
+static void ensure_successfully_mocked_calls_list_exists(void) {
if (successfully_mocked_calls == NULL) {
// successfully_mocked_calls are __func__, so there's nothing to destroy
successfully_mocked_calls = create_cgreen_vector(NULL);
}
}
-static void ensure_learned_mock_calls_list_exists() {
+static void ensure_learned_mock_calls_list_exists(void) {
if (learned_mock_calls == NULL) {
// learned_mock_calls are __func__, so there's nothing to destroy
learned_mock_calls = create_cgreen_vector(NULL);
}
}
-static void ensure_expectation_queue_exists() {
+static void ensure_expectation_queue_exists(void) {
if (global_expectation_queue == NULL) {
global_expectation_queue = create_cgreen_vector((GenericDestructor)&destroy_expectation);
}
Modified: trunk/cgreen/src/posix_runner_platform.c
===================================================================
--- trunk/cgreen/src/posix_runner_platform.c 2014-04-06 22:19:30 UTC (rev 541)
+++ trunk/cgreen/src/posix_runner_platform.c 2014-04-07 02:30:25 UTC (rev 542)
@@ -17,9 +17,9 @@
typedef void (*sighandler_t)(int);
-static int in_child_process();
-static int wait_for_child_process();
-static void stop();
+static int in_child_process(void);
+static int wait_for_child_process(void);
+static void stop(void);
static void ignore_ctrl_c(void);
static void allow_ctrl_c(void);
@@ -37,7 +37,7 @@
const int sig = WTERMSIG(status);
if (sig != SIGABRT) {
char buf[128];
- snprintf(buf, sizeof(buf), "Test terminated with signal: %s", strsignal(sig));
+ snprintf(buf, sizeof(buf), "Test terminated with signal: %s", (const char *)strsignal(sig));
(*reporter->finish_test)(reporter, test->filename, test->line, buf);
return;
}
@@ -46,7 +46,7 @@
}
}
-static int in_child_process() {
+static int in_child_process(void) {
fflush(NULL); /* Flush all buffers before forking */
pid_t child = fork();
if (child < 0) {
@@ -55,7 +55,7 @@
return ! child;
}
-static int wait_for_child_process() {
+static int wait_for_child_process(void) {
int status = 0;
ignore_ctrl_c();
wait(&status);
@@ -79,15 +79,15 @@
(void)reporter;
}
-static void stop() {
+static void stop(void) {
_exit(EXIT_SUCCESS);
}
-static void ignore_ctrl_c() {
+static void ignore_ctrl_c(void) {
signal(SIGINT, SIG_IGN);
}
-static void allow_ctrl_c() {
+static void allow_ctrl_c(void) {
signal(SIGINT, SIG_DFL);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2014-04-06 22:19:39
|
Revision: 541
http://sourceforge.net/p/cgreen/code/541
Author: matt_hargett
Date: 2014-04-06 22:19:30 +0000 (Sun, 06 Apr 2014)
Log Message:
-----------
fix win32 and cygwin builds. thanks to Dirk Jagdmann for the patch
Modified Paths:
--------------
trunk/cgreen/cmake/Modules/DefineCompilerFlags.cmake
trunk/cgreen/include/cgreen/assertions.h
trunk/cgreen/include/cgreen/cpp_constraint.h
trunk/cgreen/include/cgreen/internal/cpp_assertions.h
trunk/cgreen/src/cdash_reporter.c
trunk/cgreen/src/constraint.c
trunk/cgreen/src/messaging.c
trunk/cgreen/src/posix_cgreen_pipe.c
trunk/cgreen/src/reporter.c
trunk/cgreen/src/text_reporter.c
trunk/cgreen/src/win32_runner_platform.c
trunk/cgreen/tests/all_constraints_printout.c
Modified: trunk/cgreen/cmake/Modules/DefineCompilerFlags.cmake
===================================================================
--- trunk/cgreen/cmake/Modules/DefineCompilerFlags.cmake 2014-04-06 16:55:59 UTC (rev 540)
+++ trunk/cgreen/cmake/Modules/DefineCompilerFlags.cmake 2014-04-06 22:19:30 UTC (rev 541)
@@ -60,3 +60,10 @@
endif (WITH_FORTIFY_SOURCE)
endif (CMAKE_COMPILER_IS_GNUCC OR COMPILER_IS_CLANG)
endif (UNIX)
+
+if (WIN32)
+ if (MSVC)
+ add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
+ endif (MSVC)
+endif (WIN32)
+
Modified: trunk/cgreen/include/cgreen/assertions.h
===================================================================
--- trunk/cgreen/include/cgreen/assertions.h 2014-04-06 16:55:59 UTC (rev 540)
+++ trunk/cgreen/include/cgreen/assertions.h 2014-04-06 22:19:30 UTC (rev 541)
@@ -15,6 +15,8 @@
#endif
#ifdef __cplusplus
+#include <cgreen/cpp_assertions.h>
+
namespace cgreen {
extern "C" {
#endif
Modified: trunk/cgreen/include/cgreen/cpp_constraint.h
===================================================================
--- trunk/cgreen/include/cgreen/cpp_constraint.h 2014-04-06 16:55:59 UTC (rev 540)
+++ trunk/cgreen/include/cgreen/cpp_constraint.h 2014-04-06 22:19:30 UTC (rev 541)
@@ -1,3 +1,7 @@
+#ifndef CGREEN_CPP_CONSTRAINT
+#define CGREEN_CPP_CONSTRAINT
+
+
#include <cgreen/constraint.h>
#include <string>
@@ -3,4 +7,10 @@
namespace cgreen {
+template<typename T>
+class CppConstraint : public Constraint {
+ T expected_real_value;
+ bool (*compare)(CppConstraint *, T);
+};
+
Constraint *create_equal_to_string_constraint(const std::string& expected_value, const char *expected_value_name);
Constraint *create_not_equal_to_string_constraint(const std::string& expected_value, const char *expected_value_name);
@@ -12,6 +22,37 @@
Constraint *create_contains_string_constraint(const std::string* expected_value, const char *expected_value_name);
Constraint *create_does_not_contain_string_constraint(const std::string* expected_value, const char *expected_value_name);
+template<typename T>
+bool compare_want_value(CppConstraint<T> *constraint, T actual) {
+ return constraint->expected_real_value == actual;
+}
+
+template<typename T>
+bool compare_do_not_want_value(CppConstraint<T> *constraint, T actual) {
+ return !compare_want_value(constraint, actual);
+}
+
+template<typename T>
+void test_want_value(CppConstraint<T> *constraint, const char *function, T actual, const char *test_file, int test_line, TestReporter *reporter) {
+}
+
// TODO: add create_equal_to_constraint_<T> where operator<< output is used for expected_value name
+template<typename T>
+CppConstraint<T> *create_equal_to_value_constraint(T expected_value, const char *expected_value_name) {
+ CppConstraint<T> *constraint;// = create_cpp_constraint<T>();
+ constraint->type = VALUE_COMPARER;
+ constraint->compare = &compare_want_value;
+ constraint->execute = &test_want;
+ constraint->name = "equal";
+ constraint->expected_value = expected_value;
+ constraint->expected_value_name = expected_value_name;
+ constraint->size_of_expected_value = sizeof(intptr_t);
+ constraint->real_expected_value = expected_value;
+ return constraint;
}
+
+
+}
+
+#endif
Modified: trunk/cgreen/include/cgreen/internal/cpp_assertions.h
===================================================================
--- trunk/cgreen/include/cgreen/internal/cpp_assertions.h 2014-04-06 16:55:59 UTC (rev 540)
+++ trunk/cgreen/include/cgreen/internal/cpp_assertions.h 2014-04-06 22:19:30 UTC (rev 541)
@@ -1,5 +1,5 @@
-#ifndef CPP_ASSERTIONS_HEADER
-#define CPP_ASSERTIONS_HEADER
+#ifndef INTERNAL_CPP_ASSERTIONS_HEADER
+#define INTERNAL_CPP_ASSERTIONS_HEADER
#include <cgreen/constraint.h>
#include <stdint.h>
Modified: trunk/cgreen/src/cdash_reporter.c
===================================================================
--- trunk/cgreen/src/cdash_reporter.c 2014-04-06 16:55:59 UTC (rev 540)
+++ trunk/cgreen/src/cdash_reporter.c 2014-04-06 22:19:30 UTC (rev 541)
@@ -96,7 +96,7 @@
fclose(fd);
- strsize = snprintf(reporter_path, 255, "./Testing/%s", sbuildstamp);
+ strsize = snprintf(reporter_path, sizeof(reporter_path) - 1, "./Testing/%s", sbuildstamp);
rep_dir = mkdir(reporter_path, S_IXUSR|S_IRUSR|S_IWUSR|S_IXGRP|S_IRGRP|S_IXOTH);
Modified: trunk/cgreen/src/constraint.c
===================================================================
--- trunk/cgreen/src/constraint.c 2014-04-06 16:55:59 UTC (rev 540)
+++ trunk/cgreen/src/constraint.c 2014-04-06 22:19:30 UTC (rev 541)
@@ -13,6 +13,10 @@
#include <stdlib.h>
#include <string.h>
+#ifdef _MSC_VER
+#include "wincompat.h"
+#endif
+
#ifdef __cplusplus
namespace cgreen {
#endif
@@ -369,7 +373,7 @@
return;
}
- sprintf(parameter_name_actual_string, "[%s] parameter in [%s]", constraint->parameter_name, function);
+ snprintf(parameter_name_actual_string, sizeof(parameter_name_actual_string) - 1, "[%s] parameter in [%s]", constraint->parameter_name, function);
message = constraint->failure_message(constraint, parameter_name_actual_string, actual);
(*reporter->assert_true)(
Modified: trunk/cgreen/src/messaging.c
===================================================================
--- trunk/cgreen/src/messaging.c 2014-04-06 16:55:59 UTC (rev 540)
+++ trunk/cgreen/src/messaging.c 2014-04-06 22:19:30 UTC (rev 541)
@@ -96,7 +96,9 @@
}
void send_cgreen_message(int messaging, int result) {
- CgreenMessage *message = (CgreenMessage *) malloc(sizeof(CgreenMessage));
+ CgreenMessage *message;
+
+ message = (CgreenMessage *) malloc(sizeof(CgreenMessage));
if (message == NULL) {
return;
}
@@ -129,8 +131,8 @@
int i;
for (i = 0; i < queue_count; i++) {
if (queues[i].owner == getpid()) {
- cgreen_pipe_close(queues[i].readpipe);
- cgreen_pipe_close(queues[i].writepipe);
+ cgreen_pipe_close(queues[i].readpipe);
+ cgreen_pipe_close(queues[i].writepipe);
}
}
free(queues);
Modified: trunk/cgreen/src/posix_cgreen_pipe.c
===================================================================
--- trunk/cgreen/src/posix_cgreen_pipe.c 2014-04-06 16:55:59 UTC (rev 540)
+++ trunk/cgreen/src/posix_cgreen_pipe.c 2014-04-06 22:19:30 UTC (rev 541)
@@ -3,6 +3,12 @@
#include <unistd.h>
#include <stdio.h>
+#ifndef O_ASYNC
+# define O_ASYNC FASYNC
+# ifndef FASYNC
+# error "Your POSIX platform does not support ASYNC pipe reads. Please report a bug to cgr...@li..."
+# endif
+#endif
#ifdef __cplusplus
namespace cgreen {
@@ -21,7 +27,7 @@
ssize_t cgreen_pipe_read(int p, void *buf, size_t count)
{
- if (0 != fcntl(p, F_SETFL, O_NONBLOCK)) {
+ if (0 != fcntl(p, F_SETFL, O_ASYNC)) {
fprintf(stderr, "could not set file status flag on read pipe\n");
return -1;
}
Modified: trunk/cgreen/src/reporter.c
===================================================================
--- trunk/cgreen/src/reporter.c 2014-04-06 16:55:59 UTC (rev 540)
+++ trunk/cgreen/src/reporter.c 2014-04-06 22:19:30 UTC (rev 541)
@@ -1,6 +1,7 @@
#include <cgreen/reporter.h>
#include <cgreen/messaging.h>
#include <cgreen/breadcrumb.h>
+#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#ifndef __cplusplus
@@ -153,10 +154,13 @@
(void)arguments;
}
+static const unsigned int MAX_ASSERTIONS_PER_TEST = 8100;
+
static void assert_true(TestReporter *reporter, const char *file, int line, int result, const char *message, ...) {
va_list arguments;
+ memset(&arguments, 0, sizeof(va_list));
+
va_start(arguments, message);
-
if (result) {
(*reporter->show_pass)(reporter, file, line, message, arguments);
} else {
Modified: trunk/cgreen/src/text_reporter.c
===================================================================
--- trunk/cgreen/src/text_reporter.c 2014-04-06 16:55:59 UTC (rev 540)
+++ trunk/cgreen/src/text_reporter.c 2014-04-06 22:19:30 UTC (rev 541)
@@ -7,10 +7,10 @@
#include <stdbool.h>
#endif
-#define GREEN "\e[32m"
-#define RED "\e[31m"
-#define MAGENTA "\e[35m"
-#define RESET "\e[0m"
+#define GREEN "\x1b[32m"
+#define RED "\x1b[31m"
+#define MAGENTA "\x1b[35m"
+#define RESET "\x1b[0m"
#ifdef __cplusplus
@@ -72,9 +72,9 @@
if (reporter->options && ((TextReporterOptions *)reporter->options)->use_colours)
printf("Completed \"%s\": %s%d pass%s%s, %s%d failure%s%s, %s%d exception%s%s.\n",
name,
- reporter->passes>0?GREEN:"", reporter->passes, reporter->passes == 1 ? "" : "es", RESET,
- reporter->failures>0?RED:"", reporter->failures, reporter->failures == 1 ? "" : "s", RESET,
- reporter->exceptions>0?MAGENTA:"", reporter->exceptions, reporter->exceptions == 1 ? "" : "s", RESET);
+ (reporter->passes > 0) ? GREEN : "", reporter->passes, reporter->passes == 1 ? "" : "es", RESET,
+ (reporter->failures > 0) ? RED : "", reporter->failures, reporter->failures == 1 ? "" : "s", RESET,
+ (reporter->exceptions > 0) ? MAGENTA : "", reporter->exceptions, reporter->exceptions == 1 ? "" : "s", RESET);
else
printf("Completed \"%s\": %d pass%s, %d failure%s, %d exception%s.\n",
name, reporter->passes, reporter->passes == 1 ? "" : "es",
Modified: trunk/cgreen/src/win32_runner_platform.c
===================================================================
--- trunk/cgreen/src/win32_runner_platform.c 2014-04-06 16:55:59 UTC (rev 540)
+++ trunk/cgreen/src/win32_runner_platform.c 2014-04-06 22:19:30 UTC (rev 541)
@@ -71,7 +71,7 @@
//best solution for this.
reporter_start(reporter, testName); //add breadcrumb without triggering output to console
run_named_test_child(suite, testName, reporter);
- reporter_finish(reporter, suite->filename, suite->line);
+ reporter_finish(reporter, suite->filename, suite->line, NULL);
return; //never happens because we call stop inside run_named_test_child
}
@@ -147,7 +147,7 @@
success = CreateProcessA(fname, NULL, NULL, NULL, true, NORMAL_PRIORITY_CLASS , p_environment, NULL, &siStartupInfo, &piProcessInfo);
dispose_environment(p_environment);
WaitForSingleObject(piProcessInfo.hProcess,INFINITE);
- (*reporter->finish_test)(reporter, test->filename, test->line);
+ (*reporter->finish_test)(reporter, test->filename, test->line, NULL);
return;
}
Modified: trunk/cgreen/tests/all_constraints_printout.c
===================================================================
--- trunk/cgreen/tests/all_constraints_printout.c 2014-04-06 16:55:59 UTC (rev 540)
+++ trunk/cgreen/tests/all_constraints_printout.c 2014-04-06 22:19:30 UTC (rev 541)
@@ -130,7 +130,7 @@
}
Ensure(FailureMessage, increments_exception_count_when_terminating_via_SIGQUIT) {
- raise(SIGQUIT);
+ raise(SIGTERM);
}
#ifdef __cplusplus
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tho...@us...> - 2014-04-06 16:56:10
|
Revision: 540
http://sourceforge.net/p/cgreen/code/540
Author: thomasnilsson
Date: 2014-04-06 16:55:59 +0000 (Sun, 06 Apr 2014)
Log Message:
-----------
Added description of strict, loose and learning mocks
Modified Paths:
--------------
trunk/cgreen/doc/CMakeLists.txt
trunk/cgreen/doc/README
trunk/cgreen/doc/cgreen-guide-en.asciidoc
Property Changed:
----------------
trunk/cgreen/
Index: trunk/cgreen
===================================================================
--- trunk/cgreen 2014-04-04 21:58:09 UTC (rev 539)
+++ trunk/cgreen 2014-04-06 16:55:59 UTC (rev 540)
Property changes on: trunk/cgreen
___________________________________________________________________
Modified: svn:ignore
## -1 +1 ##
-*.a
+build
Modified: trunk/cgreen/doc/CMakeLists.txt
===================================================================
--- trunk/cgreen/doc/CMakeLists.txt 2014-04-04 21:58:09 UTC (rev 539)
+++ trunk/cgreen/doc/CMakeLists.txt 2014-04-06 16:55:59 UTC (rev 540)
@@ -1,63 +1,63 @@
-
-FIND_PACKAGE(Asciidoc)
-
-SET(ASCIIDOC_CONFFILE "${CMAKE_SOURCE_DIR}/doc/cgreen_asciidoc.conf")
-SET(A2X_ICONS_DIR "${CMAKE_SOURCE_DIR}/images/icons")
-
-OPTION(WITH_HTML "with HTML output" FALSE)
-OPTION(WITH_PDF "with PDF output" FALSE)
-
-IF(ASCIIDOC_FOUND AND WITH_HTML)
- FILE(GLOB _docfiles *.asciidoc)
- FOREACH(_file ${_docfiles})
- GET_FILENAME_COMPONENT(_file_we ${_file} NAME_WE)
- SET(_in "${_file_we}")
- SET(_out "${_file_we}.html")
- IF (NOT "${_in}" STREQUAL "CMakeLists")
- ADD_CUSTOM_COMMAND(
- OUTPUT "${_out}-html"
- COMMAND ${ASCIIDOC_EXECUTABLE} -f ${ASCIIDOC_CONFFILE}
- -a toc
- -a docinfo -o ${_out} ${_file}
- DEPENDS ${_file}
- COMMENT "Asciidoc ${_in}"
- )
- ADD_CUSTOM_TARGET(${_in}-html ALL echo
- DEPENDS "${_out}-html"
- )
- ENDIF (NOT "${_in}" STREQUAL "CMakeLists")
- ENDFOREACH(_file)
-ENDIF(ASCIIDOC_FOUND AND WITH_HTML)
-
-IF(A2X_FOUND AND WITH_PDF)
- FILE(GLOB _docfiles *.asciidoc)
- FOREACH(_file ${_docfiles})
- GET_FILENAME_COMPONENT(_file_we ${_file} NAME_WE)
- SET(_in "${_file_we}")
- SET(_out "${_file_we}.html")
-
- IF("${_in}" MATCHES "pt_BR")
- SET(LANG "pt_BR")
- ELSE("${_in}" MATCHES "pt_BR")
- SET(LANG "en_US")
- ENDIF("${_in}" MATCHES "pt_BR")
-
- IF (NOT "${_in}" STREQUAL "CMakeLists")
- ADD_CUSTOM_COMMAND(
- OUTPUT "${_out}-pdf"
- COMMAND ${A2X_EXECUTABLE} -L -f pdf -a toc --fop -d book
- --icons-dir ${A2X_ICONS_DIR}
- -a lang=${LANG}
- -a docinfo
- -a toclevels=3
- -v
- --destination-dir ${CMAKE_BINARY_DIR}/doc ${_file}
- DEPENDS ${_file}
- COMMENT "a2x ${_in}"
- )
- ADD_CUSTOM_TARGET(${_in}-pdf ALL echo
- DEPENDS "${_out}-pdf"
- )
- ENDIF (NOT "${_in}" STREQUAL "CMakeLists")
- ENDFOREACH(_file)
-ENDIF(A2X_FOUND AND WITH_PDF)
+
+FIND_PACKAGE(Asciidoc)
+
+SET(ASCIIDOC_CONFFILE "${CMAKE_SOURCE_DIR}/doc/cgreen_asciidoc.conf")
+SET(A2X_ICONS_DIR "${CMAKE_SOURCE_DIR}/images/icons")
+
+OPTION(WITH_HTML "with HTML output" FALSE)
+OPTION(WITH_PDF "with PDF output" FALSE)
+
+IF(ASCIIDOC_FOUND AND WITH_HTML)
+ FILE(GLOB _docfiles *.asciidoc)
+ FOREACH(_file ${_docfiles})
+ GET_FILENAME_COMPONENT(_file_we ${_file} NAME_WE)
+ SET(_in "${_file_we}")
+ SET(_out "${_file_we}.html")
+ IF (NOT "${_in}" STREQUAL "CMakeLists")
+ ADD_CUSTOM_COMMAND(
+ OUTPUT "${_out}-html"
+ COMMAND ${ASCIIDOC_EXECUTABLE} -f ${ASCIIDOC_CONFFILE}
+ -a toc
+ -a docinfo -o ${_out} ${_file}
+ DEPENDS ${_file}
+ COMMENT "Asciidoc ${_in}"
+ )
+ ADD_CUSTOM_TARGET(${_in}-html ALL echo
+ DEPENDS "${_out}-html"
+ )
+ ENDIF (NOT "${_in}" STREQUAL "CMakeLists")
+ ENDFOREACH(_file)
+ENDIF(ASCIIDOC_FOUND AND WITH_HTML)
+
+IF(A2X_FOUND AND WITH_PDF)
+ FILE(GLOB _docfiles *.asciidoc)
+ FOREACH(_file ${_docfiles})
+ GET_FILENAME_COMPONENT(_file_we ${_file} NAME_WE)
+ SET(_in "${_file_we}")
+ SET(_out "${_file_we}.html")
+
+ IF("${_in}" MATCHES "pt_BR")
+ SET(LANG "pt_BR")
+ ELSE("${_in}" MATCHES "pt_BR")
+ SET(LANG "en_US")
+ ENDIF("${_in}" MATCHES "pt_BR")
+
+ IF (NOT "${_in}" STREQUAL "CMakeLists")
+ ADD_CUSTOM_COMMAND(
+ OUTPUT "${_out}-pdf"
+ COMMAND ${A2X_EXECUTABLE} -L -f pdf -a toc --fop -d book
+ --icons-dir ${A2X_ICONS_DIR}
+ -a lang=${LANG}
+ -a docinfo
+ -a toclevels=3
+ -v
+ --destination-dir ${CMAKE_BINARY_DIR}/doc ${_file}
+ DEPENDS ${_file}
+ COMMENT "a2x ${_in}"
+ )
+ ADD_CUSTOM_TARGET(${_in}-pdf ALL echo
+ DEPENDS "${_out}-pdf"
+ )
+ ENDIF (NOT "${_in}" STREQUAL "CMakeLists")
+ ENDFOREACH(_file)
+ENDIF(A2X_FOUND AND WITH_PDF)
Modified: trunk/cgreen/doc/README
===================================================================
--- trunk/cgreen/doc/README 2014-04-04 21:58:09 UTC (rev 539)
+++ trunk/cgreen/doc/README 2014-04-06 16:55:59 UTC (rev 540)
@@ -1,10 +1,13 @@
-HOW-TO: Compiling the Cgreen Guide
-======================================
-
-The Cgreen Guide Book is written using Asciidoc tool.
-
-Please visit http://www.methods.co.nz/asciidoc/.
-
-Asciidoc is a wonderful way to write textual docs using Docbook as backend.
-
-You also need source-highlight (http://www.gnu.org/software/src-highlite/source-highlight.html).
+HOW-TO: Compiling the Cgreen Guide
+======================================
+
+The Cgreen Guide Book is written using Asciidoc tool. Asciidoc is a
+wonderful way to write textual docs using Docbook as backend. Please
+visit http://www.asciidoc.org for more information.
+
+You also need source-highlight (http://www.gnu.org/software/src-highlite/source-highlight.html).
+
+NOTE that on cygwin the PDF generation does not work due to some error
+in the cygwin port of 'fop' (Apache's Formatting Object
+Processor). You can use Apache's binary distribution and use the
+Windows fop.bat for the fop-step manually. thoni56/2014-04-06
Modified: trunk/cgreen/doc/cgreen-guide-en.asciidoc
===================================================================
--- trunk/cgreen/doc/cgreen-guide-en.asciidoc 2014-04-04 21:58:09 UTC (rev 539)
+++ trunk/cgreen/doc/cgreen-guide-en.asciidoc 2014-04-06 16:55:59 UTC (rev 540)
@@ -1,4 +1,4 @@
-Cgreen Unit Test for C language
+Cgreen - Unit Tests for C and C++
===============================
Cgreen Quickstart Guide
@@ -125,8 +125,9 @@
This is a very unexciting test. It just creates an empty test suite
and runs it. It's usually easier to proceed in small steps, though,
and this is the smallest one I could think of. The only complication
-is the +cgreen.h+ header file. Here I am assuming we have the *Cgreen*
-folder in the path to ensure compilation works.
+is the +cgreen.h+ header file. Here I am assuming we have the
+*Cgreen* folder in the include search path to ensure compilation
+works, otherwise you'll need to add that in the compilation command.
Building this test is, of course, trivial...
@@ -251,17 +252,20 @@
*Cgreen* has two ways of running tests. The default is to run all
tests in their own protected processes. This is what happens if you
-invoke 'run_test_suite()'. All tests then independent since they run
-in separate processes, preventing a single run-away test from bringing
-the whole program down with it.
+invoke 'run_test_suite()'. All tests are then completely independent
+since they run in separate processes, preventing a single run-away
+test from bringing the whole program down with it. It also ensures
+that one test cannot leave any state to the next, thus forcing you to
+setup the prerequisites for each test correctly and clearly.
But if you want to debug any of your tests the constant 'fork()ing'
can make that difficult or impossible. To make debugging simpler,
*Cgreen* does not fork() when only a single test is run by name with
the function 'run_single_test()'. And if you want to debug, you can
-obviously set a breakpoint at that function. But since *Cgreen* does
-some book-keeping before actually getting to the test, a better
-function is the one simply called 'run()'.
+obviously set a breakpoint at that test (but note that its actual name
+might have been mangled) . But since *Cgreen* does some book-keeping
+before actually getting to the test, a better function is the one
+simply called 'run()'.
Building this scaffolding...
@@ -651,6 +655,7 @@
mistakes very obvious. It's taken me far longer to write these
paragraphs than it has to write the code.
+
Building Cgreen test suites
---------------------------
@@ -1976,6 +1981,108 @@
All done.
+=== Mocks Are...
+
+Using mocks is a very handy way to isolate a unit and catch and
+control calls to external units. Depending on your style of coding two
+schools of thinking have emerged. And of course *Cgreen* supports
+both!
+
+
+==== Strict or Loose Mocks ====
+
+The two schools are thinking a bit differently about what mock
+expectations means. Does it mean that all external calls must be
+declared and expected? What happens if a call was made to a mock that
+wasn't expected? And vice versa, if an expected call was not made?
+
+Actually, the thinking is not only a school of thought, but you might
+want to switch from one to the other. So *Cgreen* allows for that too.
+
+By default *Cgreen* mocks are ''strict'', which means that a call to
+an non-expected mock will be considered a failure. So will an expected
+call that was not fullfilled. You might consider this a way to define
+a unit through all its exact behaviours towards its neighbours.
+
+On the other hand, ''loose'' mocks are looser. They allow both
+unfullfilled expectations and try to handle unexpected calls in a
+reasonable way.
+
+You can use both with in the same suite of tests using the call
+'cgreen_mocks_are(strict_mocks);' and 'cgreen_mocks_are(loose_mocks);'
+respectively.
+
+
+==== Learning Mocks ====
+
+Working with legacy code and trying to apply TDD, BDD or even simply
+add some unit tests is not easy. You're working with unknown code that
+does unknown things with unknown counterparts.
+
+So the first step would be to isolate the unit. We won't go into
+details on how to do that here, but basically you would replace the
+interface to other units with mocks. This is a somewhat tedious manual
+labor, but will result in an isolated unit where you can start
+applying your unit tests.
+
+Once you have your unit isolated in a harness of mocks, we need to
+figure out which calls it does to other units, now replaced by mocks,
+in the specific case we are trying to test.
+
+This might be complicated, so *Cgreen* makes that a bit simpler. There
+is a third ''mode'' of the *Cgreen* mocks, the learning mocks.
+
+If you temporarily add the call 'cgreen_mocks_are(learning_mocks);' at
+the beginning of your unit test, the mocks will record all calls and
+present a list of those calls in order, including the actual parameter
+values, on the standard output.
+
+So let's look at the following example from the *Cgreen* unit
+tests. It's a bit contorted since the test actually call the mocked
+functions directly, but I believe it will serve as an example.
+
+[source,c]
+-----
+static char *string_out(int p1) {
+ return (char *)mock(p1);
+}
+
+static int integer_out() {
+ return (int)mock();
+}
+
+Ensure(Mocks, learning_mocks_emit_pastable_code) {
+ cgreen_mocks_are(learning_mocks);
+ string_out(1);
+ string_out(2);
+ integer_out();
+ integer_out();
+ string_out(3);
+ integer_out();
+}
+-----
+
+We can see the call to 'cgreen_mocks_are()' starting the test and
+setting the mocks into learning mode.
+
+If we run this, just as we usually run tests, the following will show
+up in our terminal:
+
+[source,c]
+----
+learning_mocks_emit_pastable_code: learned mocks:
+ expect(string_out, when(p1, is_equal_to(1)));
+ expect(string_out, when(p1, is_equal_to(2)));
+ expect(integer_out);
+ expect(integer_out);
+ expect(string_out, when(p1, is_equal_to(3)));
+ expect(integer_out);
+----
+
+If this were a real test we could just copy this and paste it in place
+of the call to 'cgreen_mocks_are()' and we're done.
+
+
BDD Style Cgreen
----------------
@@ -2748,7 +2855,7 @@
well take a lot of brain power.
So, it comes as no big surprise, that sometimes you write your test
-you forget to add it to the suite. When we run it it appears that it
+and then forget to add it to the suite. When we run it it appears that it
passed on the first try! Although this *should* really make you
suspicious, sometimes you get so happy that you just continue with
churning out more tests and more code. It's not until some (possibly
@@ -2859,17 +2966,7 @@
In both these cases you need to resort to the standard, programatic,
way of invoking your tests. But, who knows...
-[appendix]
-Revision History
-----------------
-.Revisions
-[options="header"]
-|=======================
-|Revision|Description |Responsible
-|1 |Initial |JF
-|=======================
-
[appendix]
GNU Free Documentation License
------------------------------
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tho...@us...> - 2014-04-04 21:58:20
|
Revision: 539
http://sourceforge.net/p/cgreen/code/539
Author: thomasnilsson
Date: 2014-04-04 21:58:09 +0000 (Fri, 04 Apr 2014)
Log Message:
-----------
Fixed bug #12 - could not evaluate second parameter if there was no space between actual parameters in mock(). Thanks to Walter Brebels for the patch
Modified Paths:
--------------
trunk/cgreen/cmake/Modules/DefineCPackConfig.cmake
trunk/cgreen/src/mocks.c
trunk/cgreen/tests/mocks_tests.c
Modified: trunk/cgreen/cmake/Modules/DefineCPackConfig.cmake
===================================================================
--- trunk/cgreen/cmake/Modules/DefineCPackConfig.cmake 2013-12-12 16:10:33 UTC (rev 538)
+++ trunk/cgreen/cmake/Modules/DefineCPackConfig.cmake 2014-04-04 21:58:09 UTC (rev 539)
@@ -36,7 +36,7 @@
set(CPACK_GENERATOR "TGZ")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local")
- set(CPACK_PACKAGE_CONTACT "cg...@cg...")
+ set(CPACK_PACKAGE_CONTACT "Cgreen Team <cg...@cg...>")
endif(WIN32)
set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
Modified: trunk/cgreen/src/mocks.c
===================================================================
--- trunk/cgreen/src/mocks.c 2013-12-12 16:10:33 UTC (rev 538)
+++ trunk/cgreen/src/mocks.c 2014-04-04 21:58:09 UTC (rev 539)
@@ -1,695 +1,695 @@
-#include <assert.h>
-#include <cgreen/breadcrumb.h>
-#include <cgreen/mocks.h>
-#include <cgreen/parameters.h>
-#include <inttypes.h>
-// TODO: report PC-Lint bug about undeserved 451
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef __cplusplus
-namespace cgreen {
-#endif
-
-typedef struct RecordedExpectation_ {
- const char *function;
- const char *test_file;
- int test_line;
- int time_to_live;
- CgreenVector *constraints;
-} RecordedExpectation;
-
-const int UNLIMITED_TIME_TO_LIVE = 0x0f314159;
-static CgreenMockMode cgreen_mocks_are_ = strict_mocks;
-static CgreenVector *learned_mock_calls = NULL;
-static CgreenVector *successfully_mocked_calls = NULL;
-static CgreenVector *global_expectation_queue = NULL;
-
-static CgreenVector *create_vector_of_actuals(va_list actuals, int count);
-static CgreenVector *create_equal_value_constraints_for(CgreenVector *parameter_names, CgreenVector *actual_values);
-static CgreenVector *create_constraints_vector(void);
-static RecordedExpectation *create_recorded_expectation(const char *function, const char *test_file, int test_line, CgreenVector *constraints);
-static CgreenVector *constraints_vector_from_va_list(va_list constraints);
-static void destroy_expectation(RecordedExpectation *expectation);
-static void ensure_expectation_queue_exists(void);
-static void ensure_learned_mock_calls_list_exists(void);
-static void ensure_successfully_mocked_calls_list_exists(void);
-void remove_expectation_for(const char *function);
-void trigger_unfulfilled_expectations(CgreenVector *expectation_queue, TestReporter *reporter);
-RecordedExpectation *find_expectation(const char *function);
-void apply_any_read_only_parameter_constraints(RecordedExpectation *expectation, const char *parameter, intptr_t actual, TestReporter* test_reporter);
-void apply_any_content_setting_parameter_constraints(RecordedExpectation *expectation, const char *parameter, intptr_t actual, TestReporter* test_reporter);
-intptr_t stored_result_or_default_for(CgreenVector* constraints);
-int number_of_parameter_constraints_in(const CgreenVector* constraints);
-static int number_of_parameters_in(const char *parameter_list);
-bool is_always_call(RecordedExpectation* expectation);
-bool have_always_expectation_for(const char* function);
-
-bool is_never_call(RecordedExpectation* expectation);
-bool have_never_call_expectation_for(const char* function);
-
-void report_violated_never_call(TestReporter*, RecordedExpectation*);
-void report_unexpected_call(TestReporter*, RecordedExpectation*);
-void report_mock_parameter_name_not_found(TestReporter *test_reporter, RecordedExpectation *expectation, const char *parameter);
-void destroy_expectation_if_time_to_die(RecordedExpectation *expectation);
-
-void cgreen_mocks_are(CgreenMockMode mock_mode) {
- cgreen_mocks_are_ = mock_mode;
-}
-
-static int number_of_parameters_in(const char *parameter_list) {
- int count = 1;
- const char *current = parameter_list;
-
- if (strlen(parameter_list) == 0) return 0;
-
- while (*current != '\0') {
- if (*current == ' ') count++;
- current++;
- }
-
- return count;
-}
-
-int number_of_parameter_constraints_in(const CgreenVector* constraints) {
- int i, parameters = 0;
-
- for (i = 0; i < cgreen_vector_size(constraints); i++) {
- Constraint *constraint = (Constraint *)cgreen_vector_get(constraints, i);
-
- if (is_comparing(constraint)) {
- parameters++;
- }
- }
-
- return parameters;
-}
-
-void learn_mock_call_for(const char *function, const char *mock_file, int mock_line, CgreenVector *parameter_names, CgreenVector *actual_values) {
- CgreenVector *constraints = create_equal_value_constraints_for(parameter_names, actual_values);
-
- RecordedExpectation *expectation = create_recorded_expectation(function, mock_file, mock_line, constraints);
- ensure_learned_mock_calls_list_exists();
- cgreen_vector_add(learned_mock_calls, (void*)expectation);
-}
-
-void handle_missing_expectation_for(const char *function, const char *mock_file, int mock_line, CgreenVector *parameter_names, CgreenVector *actual_values, TestReporter *test_reporter) {
- RecordedExpectation *expectation;
- CgreenVector *no_constraints;
-
- switch (cgreen_mocks_are_) {
- case loose_mocks:
- break;
-
- case learning_mocks:
- learn_mock_call_for(function, mock_file, mock_line, parameter_names, actual_values);
- break;
-
- case strict_mocks:
- no_constraints = create_constraints_vector();
- expectation = create_recorded_expectation(function, mock_file, mock_line, no_constraints);
- report_unexpected_call(test_reporter, expectation);
-
- destroy_expectation(expectation);
- break;
- }
-}
-
-intptr_t mock_(TestReporter* test_reporter, const char *function, const char *mock_file, int mock_line, const char *parameters, ...) {
- va_list actuals;
- CgreenVector *actual_values;
- CgreenVector *parameter_names;
- int failures_before_read_only_constraints_executed;
- int failures_after_read_only_constraints_executed;
- int i;
- intptr_t stored_result;
- RecordedExpectation *expectation = find_expectation(function);
-
- va_start(actuals, parameters);
- actual_values = create_vector_of_actuals(actuals, number_of_parameters_in(parameters));
- va_end(actuals);
- parameter_names = create_vector_of_names(parameters);
-
- if (expectation == NULL) {
- handle_missing_expectation_for(function, mock_file, mock_line, parameter_names, actual_values, test_reporter);
- destroy_cgreen_vector(actual_values);
- destroy_cgreen_vector(parameter_names);
- return 0;
- }
-
- if (is_never_call(expectation)) {
- report_violated_never_call(test_reporter, expectation);
- destroy_cgreen_vector(actual_values);
- destroy_cgreen_vector(parameter_names);
- return 0;
- }
-
- ensure_successfully_mocked_calls_list_exists();
- cgreen_vector_add(successfully_mocked_calls, (void*)function);
-
- stored_result = stored_result_or_default_for(expectation->constraints);
-
- for (i = 0; i < cgreen_vector_size(expectation->constraints); i++) {
- Constraint *constraint = (Constraint *)cgreen_vector_get(expectation->constraints, i);
-
- if (!is_parameter(constraint)) continue;
-
- if (!constraint_is_for_parameter_in(constraint, parameters)) {
- // if expectation parameter name isn't in parameter_names,
- // fail test and skip applying constraints unlikely to match
- report_mock_parameter_name_not_found(test_reporter, expectation, constraint->parameter_name);
- destroy_expectation_if_time_to_die(expectation);
- destroy_cgreen_vector(actual_values);
- destroy_cgreen_vector(parameter_names);
-
- return stored_result;
- }
- }
-
- // if read-only constraints aren't matching, content-setting ones might corrupt memory
- // apply read-only ones first, and if they don't fail, then do the deeper constraints
- failures_before_read_only_constraints_executed = test_reporter->failures;
-
- for (i = 0; i < cgreen_vector_size(parameter_names); i++) {
- const char* parameter_name = (const char*)cgreen_vector_get(parameter_names, i);
- uintptr_t actual = (uintptr_t)cgreen_vector_get(actual_values, i);
- apply_any_read_only_parameter_constraints(expectation, parameter_name, actual, test_reporter);
- }
-
- failures_after_read_only_constraints_executed = test_reporter->failures;
-
- // FIXME: this comparison doesn't work because only parent processes' pass/fail counts are updated,
- // and even then only once they read from the pipe
- if (failures_before_read_only_constraints_executed == failures_after_read_only_constraints_executed) {
- for (i = 0; i < cgreen_vector_size(parameter_names); i++) {
- const char* parameter_name = (const char*)cgreen_vector_get(parameter_names, i);
- uintptr_t actual = (uintptr_t)cgreen_vector_get(actual_values, i);
- apply_any_content_setting_parameter_constraints(expectation, parameter_name, actual, test_reporter);
- }
- }
-
- destroy_cgreen_vector(parameter_names);
- destroy_cgreen_vector(actual_values);
-
- destroy_expectation_if_time_to_die(expectation);
-
- return stored_result;
-}
-
-
-static CgreenVector *create_vector_of_actuals(va_list actuals, int count) {
- int i;
- CgreenVector *actual_values = create_cgreen_vector(NULL);
- for (i = 0; i < count; i++) {
- uintptr_t actual = va_arg(actuals, uintptr_t);
- cgreen_vector_add(actual_values, (void*)actual);
- }
- return actual_values;
-}
-
-
-static CgreenVector *create_equal_value_constraints_for(CgreenVector *parameter_names, CgreenVector *actual_values) {
- int i;
- CgreenVector *constraints = create_constraints_vector();
- for (i = 0; i < cgreen_vector_size(parameter_names); i++) {
- const char* parameter_name = (const char*)cgreen_vector_get(parameter_names, i);
- uintptr_t actual = (uintptr_t)cgreen_vector_get(actual_values, i);
- Constraint *constraint = create_equal_to_value_constraint((intptr_t)actual, parameter_name);
- cgreen_vector_add(constraints, constraint);
- }
- return constraints;
-}
-
-
-Constraint *when_(const char *parameter, Constraint* constraint) {
- constraint->parameter_name = parameter;
- return constraint;
-}
-
-void destroy_expectation_if_time_to_die(RecordedExpectation *expectation) {
-
- if (is_always_call(expectation)) {
- return;
- }
-
- /* TODO: expectation->decrement_time_to_live_if_necessary(); if (expectation->time_to_die()) { ... } */
- expectation->time_to_live--;
-
- if (expectation->time_to_live <= 0) {
- remove_expectation_for(expectation->function);
- destroy_expectation(expectation);
- }
-}
-
-void expect_(TestReporter* test_reporter, const char *function, const char *test_file, int test_line, ...) {
- va_list constraints;
- RecordedExpectation *expectation;
- CgreenVector *constraints_vector;
-
- if (have_always_expectation_for(function)) {
- test_reporter->assert_true(
- test_reporter,
- test_file,
- test_line,
- false,
- "Mocked function [%s] already has an expectation that it will always be called a certain way; "
- "any expectations declared after an always expectation are invalid", function);
- va_start(constraints, test_line);
- destroy_constraints(constraints);
- va_end(constraints);
-
- return;
- }
-
- if (have_never_call_expectation_for(function)) {
- test_reporter->assert_true(
- test_reporter,
- test_file,
- test_line,
- false,
- "Mocked function [%s] already has an expectation that it will never be called; "
- "any expectations declared after a never call expectation are invalid", function);
- va_start(constraints, test_line);
- destroy_constraints(constraints);
- va_end(constraints);
-
- return;
- }
-
-
- va_start(constraints, test_line);
- constraints_vector = constraints_vector_from_va_list(constraints);
- expectation = create_recorded_expectation(function, test_file, test_line, constraints_vector);
- va_end(constraints);
- expectation->time_to_live = 1;
- cgreen_vector_add(global_expectation_queue, expectation);
-}
-
-void always_expect_(TestReporter* test_reporter, const char *function, const char *test_file, int test_line, ...) {
- va_list constraints;
- RecordedExpectation *expectation;
- CgreenVector *constraints_vector;
-
- if (have_always_expectation_for(function)) {
- test_reporter->assert_true(
- test_reporter,
- test_file,
- test_line,
- false,
- "Mocked function [%s] already has an expectation and will always be called a certain way; "
- "any expectations declared after an always expectation are discarded", function);
- va_start(constraints, test_line);
- destroy_constraints(constraints);
- va_end(constraints);
-
- return;
- }
-
- if (have_never_call_expectation_for(function)) {
- test_reporter->assert_true(
- test_reporter,
- test_file,
- test_line,
- false,
- "Mocked function [%s] already has an expectation that it will never be called; "
- "any expectations declared after a never call expectation are discarded", function);
- va_start(constraints, test_line);
- destroy_constraints(constraints);
- va_end(constraints);
-
- return;
- }
-
- va_start(constraints, test_line);
- constraints_vector = constraints_vector_from_va_list(constraints);
- expectation = create_recorded_expectation(function, test_file, test_line, constraints_vector);
- va_end(constraints);
- expectation->time_to_live = UNLIMITED_TIME_TO_LIVE;
- cgreen_vector_add(global_expectation_queue, expectation);
-}
-
-void never_expect_(TestReporter* test_reporter, const char *function, const char *test_file, int test_line, ...) {
- va_list constraints;
- RecordedExpectation *expectation;
- CgreenVector *constraints_vector;
-
- if (have_always_expectation_for(function)) {
- test_reporter->assert_true(
- test_reporter,
- test_file,
- test_line,
- false,
- "Mocked function [%s] already has an expectation and will always be called a certain way; "
- "declaring an expectation after an always expectation is not allowed", function);
- va_start(constraints, test_line);
- destroy_constraints(constraints);
- va_end(constraints);
-
- return;
- }
-
- if (have_never_call_expectation_for(function)) {
- test_reporter->assert_true(
- test_reporter,
- test_file,
- test_line,
- false,
- "Mocked function [%s] already has an expectation that it will never be called; "
- "declaring an expectation for a function after a never call expectation is not allowed", function);
- va_start(constraints, test_line);
- destroy_constraints(constraints);
- va_end(constraints);
-
- return;
- }
-
- va_start(constraints, test_line);
- constraints_vector = constraints_vector_from_va_list(constraints);
- expectation = create_recorded_expectation(function, test_file, test_line, constraints_vector);
- expectation->time_to_live = -UNLIMITED_TIME_TO_LIVE;
- cgreen_vector_add(global_expectation_queue, expectation);
-}
-
-
-void report_violated_never_call(TestReporter *test_reporter, RecordedExpectation* expectation) {
- test_reporter->assert_true(
- test_reporter,
- expectation->test_file,
- expectation->test_line,
- false,
- "Mocked function [%s] has an expectation that it will never be called, but it was",
- expectation->function);
-}
-
-
-static bool successfully_mocked_call(const char *function_name) {
- int i;
-
- for (i = 0; i < cgreen_vector_size(successfully_mocked_calls); i++) {
- const char *successfully_mocked_function_name = (const char *)cgreen_vector_get(successfully_mocked_calls, i);
- if (strcmp(successfully_mocked_function_name, function_name) == 0) {
- return true;
- }
- }
-
- return false;
-}
-
-
-void report_unexpected_call(TestReporter *test_reporter, RecordedExpectation* expectation) {
- const char *message;
- if (successfully_mocked_call(expectation->function)) {
- message = "Mocked function [%s] was called too many times";
- } else {
- message = "Mocked function [%s] did not have an expectation that it would be called";
- }
-
- test_reporter->assert_true(
- test_reporter,
- expectation->test_file,
- expectation->test_line,
- false,
- message,
- expectation->function);
-}
-
-void clear_mocks() {
- if (global_expectation_queue != NULL) {
- destroy_cgreen_vector(global_expectation_queue);
- global_expectation_queue = NULL;
- }
-
- if (learned_mock_calls != NULL) {
- int i;
- for (i = 0; i < cgreen_vector_size(learned_mock_calls); i++) {
- RecordedExpectation *expectation = (RecordedExpectation*)cgreen_vector_get(learned_mock_calls, i);
- destroy_expectation(expectation);
- }
-
- destroy_cgreen_vector(learned_mock_calls);
- learned_mock_calls = NULL;
- }
-}
-
-void print_learned_mocks(void) {
- int e, c;
- CgreenBreadcrumb *breadcrumb = get_test_reporter()->breadcrumb;
- printf("%s: learned mocks:\n",
- get_current_from_breadcrumb(breadcrumb));
-
- if (cgreen_vector_size(learned_mock_calls) == 0) {
- printf("\t<none>\n");
- return;
- }
-
- for (e = 0; e < cgreen_vector_size(learned_mock_calls); e++) {
- RecordedExpectation *expectation = (RecordedExpectation*)cgreen_vector_get(learned_mock_calls, e);
- const char *function_name = expectation->function;
- printf("\texpect(%s", function_name);
- for (c = 0; c < cgreen_vector_size(expectation->constraints); c++) {
- Constraint *constraint = (Constraint *)cgreen_vector_get(expectation->constraints, c);
- printf(", when(%s, is_equal_to(%" PRIdPTR "))", constraint->expected_value_name, constraint->expected_value);
- }
- printf(");\n");
- }
-}
-
-void tally_mocks(TestReporter *reporter) {
- if (cgreen_mocks_are_ == learning_mocks) {
- print_learned_mocks();
- }
-
- trigger_unfulfilled_expectations(global_expectation_queue, reporter);
- clear_mocks();
-}
-
-
-static CgreenVector *create_constraints_vector(void) {
- return create_cgreen_vector((GenericDestructor)&destroy_constraint);
-}
-
-
-static CgreenVector *constraints_vector_from_va_list(va_list constraints) {
- CgreenVector *vector = create_constraints_vector();
- Constraint *constraint;
- while ((constraint = va_arg(constraints, Constraint *)) != (Constraint *)0) {
- cgreen_vector_add(vector, constraint);
- }
- return vector;
-}
-
-
-static RecordedExpectation *create_recorded_expectation(const char *function, const char *test_file, int test_line, CgreenVector *constraints) {
- RecordedExpectation *expectation;
-
- ensure_expectation_queue_exists();
- expectation = (RecordedExpectation *)malloc(sizeof(RecordedExpectation));
- expectation->function = function;
- expectation->test_file = test_file;
- expectation->test_line = test_line;
- expectation->constraints = constraints;
-
- return expectation;
-}
-
-static void destroy_expectation(RecordedExpectation *expectation) {
- destroy_cgreen_vector(expectation->constraints);
- expectation->constraints = NULL;
- expectation->function = NULL;
- expectation->test_file = NULL;
- expectation->test_line = 0;
- expectation->time_to_live = 0;
-
- free(expectation);
-}
-
-static void ensure_successfully_mocked_calls_list_exists() {
- if (successfully_mocked_calls == NULL) {
- // successfully_mocked_calls are __func__, so there's nothing to destroy
- successfully_mocked_calls = create_cgreen_vector(NULL);
- }
-}
-
-static void ensure_learned_mock_calls_list_exists() {
- if (learned_mock_calls == NULL) {
- // learned_mock_calls are __func__, so there's nothing to destroy
- learned_mock_calls = create_cgreen_vector(NULL);
- }
-}
-
-static void ensure_expectation_queue_exists() {
- if (global_expectation_queue == NULL) {
- global_expectation_queue = create_cgreen_vector((GenericDestructor)&destroy_expectation);
- }
-}
-
-void remove_expectation_for(const char *function) {
- int i;
- for (i = 0; i < cgreen_vector_size(global_expectation_queue); i++) {
- RecordedExpectation *expectation = (RecordedExpectation *)cgreen_vector_get(global_expectation_queue, i);
-
- if (NULL == expectation) {
- printf("*** CGREEN: NULL expectation found -- maybe a previous incorrect removal?");
- continue;
- }
-
- if (strcmp(expectation->function, function) == 0) {
- cgreen_vector_remove(global_expectation_queue, i);
- return;
- }
- }
-}
-
-void trigger_unfulfilled_expectations(CgreenVector *expectation_queue, TestReporter *reporter) {
- int i;
- for (i = 0; i < cgreen_vector_size(expectation_queue); i++) {
- RecordedExpectation *expectation = (RecordedExpectation *)cgreen_vector_get(expectation_queue, i);
-
- if (NULL == expectation) {
- fprintf(stderr, "*** NULL unfulfilled cgreen expectation found -- maybe a previous incorrect removal?");
- continue;
- }
-
- if (is_always_call(expectation) || is_never_call(expectation)) {
- continue;
- }
-
- (*reporter->assert_true)(
- reporter,
- expectation->test_file,
- expectation->test_line,
- 0,
- "Expected call was not made to mocked function [%s]", expectation->function);
- }
-}
-
-RecordedExpectation *find_expectation(const char *function) {
- int i;
- for (i = 0; i < cgreen_vector_size(global_expectation_queue); i++) {
- RecordedExpectation *expectation =
- (RecordedExpectation *)cgreen_vector_get(global_expectation_queue, i);
-
- if (strcmp(expectation->function, function) == 0) {
- return expectation;
- }
- }
- return NULL;
-}
-
-void report_mock_parameter_name_not_found(TestReporter *test_reporter, RecordedExpectation *expectation, const char *constraint_parameter_name) {
-
- test_reporter->assert_true(
- test_reporter,
- expectation->test_file,
- expectation->test_line,
- false,
- "Mocked function [%s] did not define a parameter named [%s]. Did you misspell it in the expectation or forget it in the mock's argument list?",
- expectation->function,
- constraint_parameter_name);
-}
-
-void apply_any_read_only_parameter_constraints(RecordedExpectation *expectation, const char *parameter, intptr_t actual, TestReporter* test_reporter) {
- int i;
-
- for (i = 0; i < cgreen_vector_size(expectation->constraints); i++) {
- Constraint *constraint = (Constraint *)cgreen_vector_get(expectation->constraints, i);
-
- if (constraint_is_not_for_parameter(constraint, parameter)) {
- continue;
- }
-
- if (constraint->type == CONTENT_SETTER) {
- continue;
- }
-
- constraint->execute(
- constraint,
- expectation->function,
- actual,
- expectation->test_file,
- expectation->test_line,
- test_reporter);
- }
-}
-
-void apply_any_content_setting_parameter_constraints(RecordedExpectation *expectation, const char *parameter, intptr_t actual, TestReporter* test_reporter) {
- int i;
- for (i = 0; i < cgreen_vector_size(expectation->constraints); i++) {
- Constraint *constraint = (Constraint *)cgreen_vector_get(expectation->constraints, i);
-
- if (constraint_is_not_for_parameter(constraint, parameter)) {
- continue;
- }
-
- if (constraint->type != CONTENT_SETTER) {
- continue;
- }
-
- constraint->execute(
- constraint,
- expectation->function,
- actual,
- expectation->test_file,
- expectation->test_line,
- test_reporter);
- }
-}
-
-intptr_t stored_result_or_default_for(CgreenVector* constraints) {
- int i;
- for (i = 0; i < cgreen_vector_size(constraints); i++) {
- Constraint *constraint = (Constraint *)cgreen_vector_get(constraints, i);
-
- if (constraint->type == RETURN_VALUE) {
- return constraint->expected_value;
- }
- }
-
- return 0;
-}
-
-bool is_always_call(RecordedExpectation* expectation) {
- return expectation->time_to_live == UNLIMITED_TIME_TO_LIVE;
-}
-
-bool have_always_expectation_for(const char* function) {
- int i;
- for (i = 0; i < cgreen_vector_size(global_expectation_queue); i++) {
- RecordedExpectation *expectation =
- (RecordedExpectation *)cgreen_vector_get(global_expectation_queue, i);
- if (strcmp(expectation->function, function) == 0) {
- if (is_always_call(expectation)) {
- return true;
- }
- }
- }
-
- return false;
-}
-
-bool is_never_call(RecordedExpectation* expectation) {
- return expectation->time_to_live == -UNLIMITED_TIME_TO_LIVE;
-}
-
-bool have_never_call_expectation_for(const char* function) {
- int i;
- for (i = 0; i < cgreen_vector_size(global_expectation_queue); i++) {
- RecordedExpectation *expectation =
- (RecordedExpectation *)cgreen_vector_get(global_expectation_queue, i);
- if (strcmp(expectation->function, function) == 0) {
- if (is_never_call(expectation)) {
- return true;
- }
- }
- }
-
- return false;
-}
-
-#ifdef __cplusplus
-} // namespace cgreen
-#endif
-
-/* vim: set ts=4 sw=4 et cindent: */
+#include <assert.h>
+#include <cgreen/breadcrumb.h>
+#include <cgreen/mocks.h>
+#include <cgreen/parameters.h>
+#include <inttypes.h>
+// TODO: report PC-Lint bug about undeserved 451
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef __cplusplus
+namespace cgreen {
+#endif
+
+typedef struct RecordedExpectation_ {
+ const char *function;
+ const char *test_file;
+ int test_line;
+ int time_to_live;
+ CgreenVector *constraints;
+} RecordedExpectation;
+
+const int UNLIMITED_TIME_TO_LIVE = 0x0f314159;
+static CgreenMockMode cgreen_mocks_are_ = strict_mocks;
+static CgreenVector *learned_mock_calls = NULL;
+static CgreenVector *successfully_mocked_calls = NULL;
+static CgreenVector *global_expectation_queue = NULL;
+
+static CgreenVector *create_vector_of_actuals(va_list actuals, int count);
+static CgreenVector *create_equal_value_constraints_for(CgreenVector *parameter_names, CgreenVector *actual_values);
+static CgreenVector *create_constraints_vector(void);
+static RecordedExpectation *create_recorded_expectation(const char *function, const char *test_file, int test_line, CgreenVector *constraints);
+static CgreenVector *constraints_vector_from_va_list(va_list constraints);
+static void destroy_expectation(RecordedExpectation *expectation);
+static void ensure_expectation_queue_exists(void);
+static void ensure_learned_mock_calls_list_exists(void);
+static void ensure_successfully_mocked_calls_list_exists(void);
+void remove_expectation_for(const char *function);
+void trigger_unfulfilled_expectations(CgreenVector *expectation_queue, TestReporter *reporter);
+RecordedExpectation *find_expectation(const char *function);
+void apply_any_read_only_parameter_constraints(RecordedExpectation *expectation, const char *parameter, intptr_t actual, TestReporter* test_reporter);
+void apply_any_content_setting_parameter_constraints(RecordedExpectation *expectation, const char *parameter, intptr_t actual, TestReporter* test_reporter);
+intptr_t stored_result_or_default_for(CgreenVector* constraints);
+int number_of_parameter_constraints_in(const CgreenVector* constraints);
+static int number_of_parameters_in(const char *parameter_list);
+bool is_always_call(RecordedExpectation* expectation);
+bool have_always_expectation_for(const char* function);
+
+bool is_never_call(RecordedExpectation* expectation);
+bool have_never_call_expectation_for(const char* function);
+
+void report_violated_never_call(TestReporter*, RecordedExpectation*);
+void report_unexpected_call(TestReporter*, RecordedExpectation*);
+void report_mock_parameter_name_not_found(TestReporter *test_reporter, RecordedExpectation *expectation, const char *parameter);
+void destroy_expectation_if_time_to_die(RecordedExpectation *expectation);
+
+void cgreen_mocks_are(CgreenMockMode mock_mode) {
+ cgreen_mocks_are_ = mock_mode;
+}
+
+static int number_of_parameters_in(const char *parameter_list) {
+ int count = 1;
+ const char *current = parameter_list;
+
+ if (strlen(parameter_list) == 0) return 0;
+
+ while (*current != '\0') {
+ if (*current == ',') count++;
+ current++;
+ }
+
+ return count;
+}
+
+int number_of_parameter_constraints_in(const CgreenVector* constraints) {
+ int i, parameters = 0;
+
+ for (i = 0; i < cgreen_vector_size(constraints); i++) {
+ Constraint *constraint = (Constraint *)cgreen_vector_get(constraints, i);
+
+ if (is_comparing(constraint)) {
+ parameters++;
+ }
+ }
+
+ return parameters;
+}
+
+void learn_mock_call_for(const char *function, const char *mock_file, int mock_line, CgreenVector *parameter_names, CgreenVector *actual_values) {
+ CgreenVector *constraints = create_equal_value_constraints_for(parameter_names, actual_values);
+
+ RecordedExpectation *expectation = create_recorded_expectation(function, mock_file, mock_line, constraints);
+ ensure_learned_mock_calls_list_exists();
+ cgreen_vector_add(learned_mock_calls, (void*)expectation);
+}
+
+void handle_missing_expectation_for(const char *function, const char *mock_file, int mock_line, CgreenVector *parameter_names, CgreenVector *actual_values, TestReporter *test_reporter) {
+ RecordedExpectation *expectation;
+ CgreenVector *no_constraints;
+
+ switch (cgreen_mocks_are_) {
+ case loose_mocks:
+ break;
+
+ case learning_mocks:
+ learn_mock_call_for(function, mock_file, mock_line, parameter_names, actual_values);
+ break;
+
+ case strict_mocks:
+ no_constraints = create_constraints_vector();
+ expectation = create_recorded_expectation(function, mock_file, mock_line, no_constraints);
+ report_unexpected_call(test_reporter, expectation);
+
+ destroy_expectation(expectation);
+ break;
+ }
+}
+
+intptr_t mock_(TestReporter* test_reporter, const char *function, const char *mock_file, int mock_line, const char *parameters, ...) {
+ va_list actuals;
+ CgreenVector *actual_values;
+ CgreenVector *parameter_names;
+ int failures_before_read_only_constraints_executed;
+ int failures_after_read_only_constraints_executed;
+ int i;
+ intptr_t stored_result;
+ RecordedExpectation *expectation = find_expectation(function);
+
+ va_start(actuals, parameters);
+ actual_values = create_vector_of_actuals(actuals, number_of_parameters_in(parameters));
+ va_end(actuals);
+ parameter_names = create_vector_of_names(parameters);
+
+ if (expectation == NULL) {
+ handle_missing_expectation_for(function, mock_file, mock_line, parameter_names, actual_values, test_reporter);
+ destroy_cgreen_vector(actual_values);
+ destroy_cgreen_vector(parameter_names);
+ return 0;
+ }
+
+ if (is_never_call(expectation)) {
+ report_violated_never_call(test_reporter, expectation);
+ destroy_cgreen_vector(actual_values);
+ destroy_cgreen_vector(parameter_names);
+ return 0;
+ }
+
+ ensure_successfully_mocked_calls_list_exists();
+ cgreen_vector_add(successfully_mocked_calls, (void*)function);
+
+ stored_result = stored_result_or_default_for(expectation->constraints);
+
+ for (i = 0; i < cgreen_vector_size(expectation->constraints); i++) {
+ Constraint *constraint = (Constraint *)cgreen_vector_get(expectation->constraints, i);
+
+ if (!is_parameter(constraint)) continue;
+
+ if (!constraint_is_for_parameter_in(constraint, parameters)) {
+ // if expectation parameter name isn't in parameter_names,
+ // fail test and skip applying constraints unlikely to match
+ report_mock_parameter_name_not_found(test_reporter, expectation, constraint->parameter_name);
+ destroy_expectation_if_time_to_die(expectation);
+ destroy_cgreen_vector(actual_values);
+ destroy_cgreen_vector(parameter_names);
+
+ return stored_result;
+ }
+ }
+
+ // if read-only constraints aren't matching, content-setting ones might corrupt memory
+ // apply read-only ones first, and if they don't fail, then do the deeper constraints
+ failures_before_read_only_constraints_executed = test_reporter->failures;
+
+ for (i = 0; i < cgreen_vector_size(parameter_names); i++) {
+ const char* parameter_name = (const char*)cgreen_vector_get(parameter_names, i);
+ uintptr_t actual = (uintptr_t)cgreen_vector_get(actual_values, i);
+ apply_any_read_only_parameter_constraints(expectation, parameter_name, actual, test_reporter);
+ }
+
+ failures_after_read_only_constraints_executed = test_reporter->failures;
+
+ // FIXME: this comparison doesn't work because only parent processes' pass/fail counts are updated,
+ // and even then only once they read from the pipe
+ if (failures_before_read_only_constraints_executed == failures_after_read_only_constraints_executed) {
+ for (i = 0; i < cgreen_vector_size(parameter_names); i++) {
+ const char* parameter_name = (const char*)cgreen_vector_get(parameter_names, i);
+ uintptr_t actual = (uintptr_t)cgreen_vector_get(actual_values, i);
+ apply_any_content_setting_parameter_constraints(expectation, parameter_name, actual, test_reporter);
+ }
+ }
+
+ destroy_cgreen_vector(parameter_names);
+ destroy_cgreen_vector(actual_values);
+
+ destroy_expectation_if_time_to_die(expectation);
+
+ return stored_result;
+}
+
+
+static CgreenVector *create_vector_of_actuals(va_list actuals, int count) {
+ int i;
+ CgreenVector *actual_values = create_cgreen_vector(NULL);
+ for (i = 0; i < count; i++) {
+ uintptr_t actual = va_arg(actuals, uintptr_t);
+ cgreen_vector_add(actual_values, (void*)actual);
+ }
+ return actual_values;
+}
+
+
+static CgreenVector *create_equal_value_constraints_for(CgreenVector *parameter_names, CgreenVector *actual_values) {
+ int i;
+ CgreenVector *constraints = create_constraints_vector();
+ for (i = 0; i < cgreen_vector_size(parameter_names); i++) {
+ const char* parameter_name = (const char*)cgreen_vector_get(parameter_names, i);
+ uintptr_t actual = (uintptr_t)cgreen_vector_get(actual_values, i);
+ Constraint *constraint = create_equal_to_value_constraint((intptr_t)actual, parameter_name);
+ cgreen_vector_add(constraints, constraint);
+ }
+ return constraints;
+}
+
+
+Constraint *when_(const char *parameter, Constraint* constraint) {
+ constraint->parameter_name = parameter;
+ return constraint;
+}
+
+void destroy_expectation_if_time_to_die(RecordedExpectation *expectation) {
+
+ if (is_always_call(expectation)) {
+ return;
+ }
+
+ /* TODO: expectation->decrement_time_to_live_if_necessary(); if (expectation->time_to_die()) { ... } */
+ expectation->time_to_live--;
+
+ if (expectation->time_to_live <= 0) {
+ remove_expectation_for(expectation->function);
+ destroy_expectation(expectation);
+ }
+}
+
+void expect_(TestReporter* test_reporter, const char *function, const char *test_file, int test_line, ...) {
+ va_list constraints;
+ RecordedExpectation *expectation;
+ CgreenVector *constraints_vector;
+
+ if (have_always_expectation_for(function)) {
+ test_reporter->assert_true(
+ test_reporter,
+ test_file,
+ test_line,
+ false,
+ "Mocked function [%s] already has an expectation that it will always be called a certain way; "
+ "any expectations declared after an always expectation are invalid", function);
+ va_start(constraints, test_line);
+ destroy_constraints(constraints);
+ va_end(constraints);
+
+ return;
+ }
+
+ if (have_never_call_expectation_for(function)) {
+ test_reporter->assert_true(
+ test_reporter,
+ test_file,
+ test_line,
+ false,
+ "Mocked function [%s] already has an expectation that it will never be called; "
+ "any expectations declared after a never call expectation are invalid", function);
+ va_start(constraints, test_line);
+ destroy_constraints(constraints);
+ va_end(constraints);
+
+ return;
+ }
+
+
+ va_start(constraints, test_line);
+ constraints_vector = constraints_vector_from_va_list(constraints);
+ expectation = create_recorded_expectation(function, test_file, test_line, constraints_vector);
+ va_end(constraints);
+ expectation->time_to_live = 1;
+ cgreen_vector_add(global_expectation_queue, expectation);
+}
+
+void always_expect_(TestReporter* test_reporter, const char *function, const char *test_file, int test_line, ...) {
+ va_list constraints;
+ RecordedExpectation *expectation;
+ CgreenVector *constraints_vector;
+
+ if (have_always_expectation_for(function)) {
+ test_reporter->assert_true(
+ test_reporter,
+ test_file,
+ test_line,
+ false,
+ "Mocked function [%s] already has an expectation and will always be called a certain way; "
+ "any expectations declared after an always expectation are discarded", function);
+ va_start(constraints, test_line);
+ destroy_constraints(constraints);
+ va_end(constraints);
+
+ return;
+ }
+
+ if (have_never_call_expectation_for(function)) {
+ test_reporter->assert_true(
+ test_reporter,
+ test_file,
+ test_line,
+ false,
+ "Mocked function [%s] already has an expectation that it will never be called; "
+ "any expectations declared after a never call expectation are discarded", function);
+ va_start(constraints, test_line);
+ destroy_constraints(constraints);
+ va_end(constraints);
+
+ return;
+ }
+
+ va_start(constraints, test_line);
+ constraints_vector = constraints_vector_from_va_list(constraints);
+ expectation = create_recorded_expectation(function, test_file, test_line, constraints_vector);
+ va_end(constraints);
+ expectation->time_to_live = UNLIMITED_TIME_TO_LIVE;
+ cgreen_vector_add(global_expectation_queue, expectation);
+}
+
+void never_expect_(TestReporter* test_reporter, const char *function, const char *test_file, int test_line, ...) {
+ va_list constraints;
+ RecordedExpectation *expectation;
+ CgreenVector *constraints_vector;
+
+ if (have_always_expectation_for(function)) {
+ test_reporter->assert_true(
+ test_reporter,
+ test_file,
+ test_line,
+ false,
+ "Mocked function [%s] already has an expectation and will always be called a certain way; "
+ "declaring an expectation after an always expectation is not allowed", function);
+ va_start(constraints, test_line);
+ destroy_constraints(constraints);
+ va_end(constraints);
+
+ return;
+ }
+
+ if (have_never_call_expectation_for(function)) {
+ test_reporter->assert_true(
+ test_reporter,
+ test_file,
+ test_line,
+ false,
+ "Mocked function [%s] already has an expectation that it will never be called; "
+ "declaring an expectation for a function after a never call expectation is not allowed", function);
+ va_start(constraints, test_line);
+ destroy_constraints(constraints);
+ va_end(constraints);
+
+ return;
+ }
+
+ va_start(constraints, test_line);
+ constraints_vector = constraints_vector_from_va_list(constraints);
+ expectation = create_recorded_expectation(function, test_file, test_line, constraints_vector);
+ expectation->time_to_live = -UNLIMITED_TIME_TO_LIVE;
+ cgreen_vector_add(global_expectation_queue, expectation);
+}
+
+
+void report_violated_never_call(TestReporter *test_reporter, RecordedExpectation* expectation) {
+ test_reporter->assert_true(
+ test_reporter,
+ expectation->test_file,
+ expectation->test_line,
+ false,
+ "Mocked function [%s] has an expectation that it will never be called, but it was",
+ expectation->function);
+}
+
+
+static bool successfully_mocked_call(const char *function_name) {
+ int i;
+
+ for (i = 0; i < cgreen_vector_size(successfully_mocked_calls); i++) {
+ const char *successfully_mocked_function_name = (const char *)cgreen_vector_get(successfully_mocked_calls, i);
+ if (strcmp(successfully_mocked_function_name, function_name) == 0) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
+void report_unexpected_call(TestReporter *test_reporter, RecordedExpectation* expectation) {
+ const char *message;
+ if (successfully_mocked_call(expectation->function)) {
+ message = "Mocked function [%s] was called too many times";
+ } else {
+ message = "Mocked function [%s] did not have an expectation that it would be called";
+ }
+
+ test_reporter->assert_true(
+ test_reporter,
+ expectation->test_file,
+ expectation->test_line,
+ false,
+ message,
+ expectation->function);
+}
+
+void clear_mocks() {
+ if (global_expectation_queue != NULL) {
+ destroy_cgreen_vector(global_expectation_queue);
+ global_expectation_queue = NULL;
+ }
+
+ if (learned_mock_calls != NULL) {
+ int i;
+ for (i = 0; i < cgreen_vector_size(learned_mock_calls); i++) {
+ RecordedExpectation *expectation = (RecordedExpectation*)cgreen_vector_get(learned_mock_calls, i);
+ destroy_expectation(expectation);
+ }
+
+ destroy_cgreen_vector(learned_mock_calls);
+ learned_mock_calls = NULL;
+ }
+}
+
+void print_learned_mocks(void) {
+ int e, c;
+ CgreenBreadcrumb *breadcrumb = get_test_reporter()->breadcrumb;
+ printf("%s: learned mocks:\n",
+ get_current_from_breadcrumb(breadcrumb));
+
+ if (cgreen_vector_size(learned_mock_calls) == 0) {
+ printf("\t<none>\n");
+ return;
+ }
+
+ for (e = 0; e < cgreen_vector_size(learned_mock_calls); e++) {
+ RecordedExpectation *expectation = (RecordedExpectation*)cgreen_vector_get(learned_mock_calls, e);
+ const char *function_name = expectation->function;
+ printf("\texpect(%s", function_name);
+ for (c = 0; c < cgreen_vector_size(expectation->constraints); c++) {
+ Constraint *constraint = (Constraint *)cgreen_vector_get(expectation->constraints, c);
+ printf(", when(%s, is_equal_to(%" PRIdPTR "))", constraint->expected_value_name, constraint->expected_value);
+ }
+ printf(");\n");
+ }
+}
+
+void tally_mocks(TestReporter *reporter) {
+ if (cgreen_mocks_are_ == learning_mocks) {
+ print_learned_mocks();
+ }
+
+ trigger_unfulfilled_expectations(global_expectation_queue, reporter);
+ clear_mocks();
+}
+
+
+static CgreenVector *create_constraints_vector(void) {
+ return create_cgreen_vector((GenericDestructor)&destroy_constraint);
+}
+
+
+static CgreenVector *constraints_vector_from_va_list(va_list constraints) {
+ CgreenVector *vector = create_constraints_vector();
+ Constraint *constraint;
+ while ((constraint = va_arg(constraints, Constraint *)) != (Constraint *)0) {
+ cgreen_vector_add(vector, constraint);
+ }
+ return vector;
+}
+
+
+static RecordedExpectation *create_recorded_expectation(const char *function, const char *test_file, int test_line, CgreenVector *constraints) {
+ RecordedExpectation *expectation;
+
+ ensure_expectation_queue_exists();
+ expectation = (RecordedExpectation *)malloc(sizeof(RecordedExpectation));
+ expectation->function = function;
+ expectation->test_file = test_file;
+ expectation->test_line = test_line;
+ expectation->constraints = constraints;
+
+ return expectation;
+}
+
+static void destroy_expectation(RecordedExpectation *expectation) {
+ destroy_cgreen_vector(expectation->constraints);
+ expectation->constraints = NULL;
+ expectation->function = NULL;
+ expectation->test_file = NULL;
+ expectation->test_line = 0;
+ expectation->time_to_live = 0;
+
+ free(expectation);
+}
+
+static void ensure_successfully_mocked_calls_list_exists() {
+ if (successfully_mocked_calls == NULL) {
+ // successfully_mocked_calls are __func__, so there's nothing to destroy
+ successfully_mocked_calls = create_cgreen_vector(NULL);
+ }
+}
+
+static void ensure_learned_mock_calls_list_exists() {
+ if (learned_mock_calls == NULL) {
+ // learned_mock_calls are __func__, so there's nothing to destroy
+ learned_mock_calls = create_cgreen_vector(NULL);
+ }
+}
+
+static void ensure_expectation_queue_exists() {
+ if (global_expectation_queue == NULL) {
+ global_expectation_queue = create_cgreen_vector((GenericDestructor)&destroy_expectation);
+ }
+}
+
+void remove_expectation_for(const char *function) {
+ int i;
+ for (i = 0; i < cgreen_vector_size(global_expectation_queue); i++) {
+ RecordedExpectation *expectation = (RecordedExpectation *)cgreen_vector_get(global_expectation_queue, i);
+
+ if (NULL == expectation) {
+ printf("*** CGREEN: NULL expectation found -- maybe a previous incorrect removal?");
+ continue;
+ }
+
+ if (strcmp(expectation->function, function) == 0) {
+ cgreen_vector_remove(global_expectation_queue, i);
+ return;
+ }
+ }
+}
+
+void trigger_unfulfilled_expectations(CgreenVector *expectation_queue, TestReporter *reporter) {
+ int i;
+ for (i = 0; i < cgreen_vector_size(expectation_queue); i++) {
+ RecordedExpectation *expectation = (RecordedExpectation *)cgreen_vector_get(expectation_queue, i);
+
+ if (NULL == expectation) {
+ fprintf(stderr, "*** NULL unfulfilled cgreen expectation found -- maybe a previous incorrect removal?");
+ continue;
+ }
+
+ if (is_always_call(expectation) || is_never_call(expectation)) {
+ continue;
+ }
+
+ (*reporter->assert_true)(
+ reporter,
+ expectation->test_file,
+ expectation->test_line,
+ 0,
+ "Expected call was not made to mocked function [%s]", expectation->function);
+ }
+}
+
+RecordedExpectation *find_expectation(const char *function) {
+ int i;
+ for (i = 0; i < cgreen_vector_size(global_expectation_queue); i++) {
+ RecordedExpectation *expectation =
+ (RecordedExpectation *)cgreen_vector_get(global_expectation_queue, i);
+
+ if (strcmp(expectation->function, function) == 0) {
+ return expectation;
+ }
+ }
+ return NULL;
+}
+
+void report_mock_parameter_name_not_found(TestReporter *test_reporter, RecordedExpectation *expectation, const char *constraint_parameter_name) {
+
+ test_reporter->assert_true(
+ test_reporter,
+ expectation->test_file,
+ expectation->test_line,
+ false,
+ "Mocked function [%s] did not define a parameter named [%s]. Did you misspell it in the expectation or forget it in the mock's argument list?",
+ expectation->function,
+ constraint_parameter_name);
+}
+
+void apply_any_read_only_parameter_constraints(RecordedExpectation *expectation, const char *parameter, intptr_t actual, TestReporter* test_reporter) {
+ int i;
+
+ for (i = 0; i < cgreen_vector_size(expectation->constraints); i++) {
+ Constraint *constraint = (Constraint *)cgreen_vector_get(expectation->constraints, i);
+
+ if (constraint_is_not_for_parameter(constraint, parameter)) {
+ continue;
+ }
+
+ if (constraint->type == CONTENT_SETTER) {
+ continue;
+ }
+
+ constraint->execute(
+ constraint,
+ expectation->function,
+ actual,
+ expectation->test_file,
+ expectation->test_line,
+ test_reporter);
+ }
+}
+
+void apply_any_content_setting_parameter_constraints(RecordedExpectation *expectation, const char *parameter, intptr_t actual, TestReporter* test_reporter) {
+ int i;
+ for (i = 0; i < cgreen_vector_size(expectation->constraints); i++) {
+ Constraint *constraint = (Constraint *)cgreen_vector_get(expectation->constraints, i);
+
+ if (constraint_is_not_for_parameter(constraint, parameter)) {
+ continue;
+ }
+
+ if (constraint->type != CONTENT_SETTER) {
+ continue;
+ }
+
+ constraint->execute(
+ constraint,
+ expectation->function,
+ actual,
+ expectation->test_file,
+ expectation->test_line,
+ test_reporter);
+ }
+}
+
+intptr_t stored_result_or_default_for(CgreenVector* constraints) {
+ int i;
+ for (i = 0; i < cgreen_vector_size(constraints); i++) {
+ Constraint *constraint = (Constraint *)cgreen_vector_get(constraints, i);
+
+ if (constraint->type == RETURN_VALUE) {
+ return constraint->expected_value;
+ }
+ }
+
+ return 0;
+}
+
+bool is_always_call(RecordedExpectation* expectation) {
+ return expectation->time_to_live == UNLIMITED_TIME_TO_LIVE;
+}
+
+bool have_always_expectation_for(const char* function) {
+ int i;
+ for (i = 0; i < cgreen_vector_size(global_expectation_queue); i++) {
+ RecordedExpectation *expectation =
+ (RecordedExpectation *)cgreen_vector_get(global_expectation_queue, i);
+ if (strcmp(expectation->function, function) == 0) {
+ if (is_always_call(expectation)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+bool is_never_call(RecordedExpectation* expectation) {
+ return expectation->time_to_live == -UNLIMITED_TIME_TO_LIVE;
+}
+
+bool have_never_call_expectation_for(const char* function) {
+ int i;
+ for (i = 0; i < cgreen_vector_size(global_expectation_queue); i++) {
+ RecordedExpectation *expectation =
+ (RecordedExpectation *)cgreen_vector_get(global_expectation_queue, i);
+ if (strcmp(expectation->function, function) == 0) {
+ if (is_never_call(expectation)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+#ifdef __cplusplus
+} // namespace cgreen
+#endif
+
+/* vim: set ts=4 sw=4 et cindent: */
Modified: trunk/cgreen/tests/mocks_tests.c
===================================================================
--- trunk/cgreen/tests/mocks_tests.c 2013-12-12 16:10:33 UTC (rev 538)
+++ trunk/cgreen/tests/mocks_tests.c 2014-04-04 21:58:09 UTC (rev 539)
@@ -1,375 +1,389 @@
-#include <cgreen/boxed_double.h>
-#include <cgreen/cgreen.h>
-#include <cgreen/mocks.h>
-#include <cgreen/unit.h>
-#include <stdlib.h>
-
-#ifdef __cplusplus
-using namespace cgreen;
-#endif
-
-Describe(Mocks);
-BeforeEach(Mocks) {}
-AfterEach(Mocks) {}
-
-static int integer_out() {
- return (int)mock();
-}
-
-Ensure(Mocks, default_return_value_when_no_presets_for_loose_mock) {
- cgreen_mocks_are(loose_mocks);
- assert_that(integer_out(), is_equal_to(0));
-}
-
-Ensure(Mocks, can_stub_an_integer_return) {
- expect(integer_out,
- will_return(3)
- );
-
- assert_that(integer_out(), is_equal_to(3));
-}
-
-Ensure(Mocks, repeats_return_value_when_set_to_always) {
- always_expect(integer_out,
- will_return(3)
- );
-
- assert_that(integer_out(), is_equal_to(3));
- assert_that(integer_out(), is_equal_to(3));
-}
-
-Ensure(Mocks, can_stub_an_integer_return_sequence) {
- expect(integer_out,
- will_return(1)
- );
-
- expect(integer_out,
- will_return(2)
- );
-
- expect(integer_out,
- will_return(3)
- );
-
- assert_that(integer_out(), is_equal_to(1));
- assert_that(integer_out(), is_equal_to(2));
- assert_that(integer_out(), is_equal_to(3));
-}
-
-Ensure(Mocks, expectations_are_reset_between_tests_with_loose_mocks) {
- cgreen_mocks_are(loose_mocks);
- assert_that(integer_out(), is_equal_to(0));
-}
-
-static char *string_out(int p1) {
- return (char *)mock(p1);
-}
-
-Ensure(Mocks, can_stub_a_string_return) {
- expect(string_out, will_return("hello"));
- assert_string_equal(string_out(1), "hello");
-}
-
-Ensure(Mocks, can_stub_a_string_sequence) {
- expect(string_out, will_return("hello"));
- expect(string_out, will_return("goodbye"));
-
- assert_string_equal(string_out(2), "hello");
- assert_string_equal(string_out(3), "goodbye");
-}
-
-static void integer_in(int i) {
- mock(i);
-}
-
-Ensure(Mocks, expecting_once_with_any_parameters) {
- expect(integer_in);
- integer_in(3);
-}
-
-Ensure(Mocks, expecting_once_with_parameter_checks_that_parameter) {
- expect(integer_in, when(i, is_equal_to(3)));
- integer_in(3);
-}
-
-Ensure(Mocks, always_expect_keeps_affirming_parameter) {
- always_expect(integer_in, when(i, is_equal_to(3)));
- integer_in(3);
- integer_in(3);
- integer_in(3);
-}
-
-Ensure(Mocks, expect_a_sequence) {
- expect(integer_in, when(i, is_equal_to(1)));
- expect(integer_in, when(i, is_equal_to(2)));
- expect(integer_in, when(i, is_equal_to(3)));
- integer_in(1);
- integer_in(2);
- integer_in(3);
-}
-
-static void string_in(const char *s) {
- mock(s);
-}
-
-Ensure(Mocks, string_expect_is_confirmed) {
- expect(string_in, when(s, is_equal_to_string("hello")));
- string_in("hello");
-}
-
-Ensure(Mocks, string_contains_expectation_is_confirmed) {
- expect(string_in, when(s, contains_string("hello")));
- string_in("alice, hello");
-}
-
-Ensure(Mocks, string_expect_is_confirmed_even_when_null) {
- expect(string_in, when(s, is_equal_to_string((char *)NULL)));
- string_in(NULL);
-}
-
-Ensure(Mocks, string_expect_sequence) {
- expect(string_in, when(s, is_equal_to_string("hello")));
- expect(string_in, when(s, is_equal_to_string("goodbye")));
- string_in("hello");
- string_in("goodbye");
-}
-
-Ensure(Mocks, expecting_once_with_non_null_parameter_checks_that_parameter) {
- expect(string_in, when(s, is_non_null));
- string_in("anything");
-}
-
-static void double_in(double d) {
- mock(box_double(d));
-}
-
-Ensure(Mocks, double_expect_is_confirmed) {
- expect(double_in, when(d, is_equal_to_double(3.14)));
- double_in(3.14);
-}
-
-Ensure(Mocks, double_expect_sequence) {
- expect(double_in, when(d, is_equal_to_double(1.0)));
- expect(double_in, when(d, is_equal_to_double(2.0)));
- double_in(1.0);
- double_in(2.0);
-}
-
-static void mixed_parameters(int i, const char *s) {
- mock(i, s);
-}
-
-Ensure(Mocks, confirming_multiple_parameters_multiple_times) {
- expect(mixed_parameters,
- when(i, is_equal_to(1)),
- when(s, is_equal_to_string("Hello"))
- );
- expect(mixed_parameters,
- when(i, is_equal_to(2)),
- when(s, is_equal_to_string("Goodbye"))
- );
-
- mixed_parameters(1, "Hello");
- mixed_parameters(2, "Goodbye");
-}
-
-static int sample_mock(int i, const char *s) {
- return (int)mock(i, s);
-}
-
-Ensure(Mocks, can_mock_full_function_call) {
- expect(sample_mock,
- will_return(5),
- when(i, is_equal_to(666)),
- when(s, is_equal_to_string("devil"))
- );
-
- assert_that(sample_mock(666, "devil"), is_equal_to(5));
-}
-
-Ensure(Mocks, when_called_with_always_should_not_tally_counts) {
- always_expect(string_out,
- will_return(5),
- when(i, is_equal_to(666)),
- when(s, is_equal_to_string("devil"))
- );
-}
-
-Ensure(Mocks, can_mock_full_sequence) {
- expect(sample_mock,
- will_return(5),
- when(i, is_equal_to(666)),
- when(s, is_equal_to_string("devil"))
- );
-
- expect(sample_mock,
- will_return(6),
- when(i, is_equal_to(667)),
- when(s, is_equal_to_string("beastie"))
- );
-
- assert_that(sample_mock(666, "devil"), is_equal_to(5));
- assert_that(sample_mock(667, "beastie"), is_equal_to(6));
-}
-
-Ensure(Mocks, can_always_mock_full_function_call) {
- always_expect(sample_mock,
- will_return(5),
- when(i, is_equal_to(666)),
- when(s, is_equal_to_string("devil"))
- );
-
- assert_that(sample_mock(666, "devil"), is_equal_to(5));
- assert_that(sample_mock(666, "devil"), is_equal_to(5));
- assert_that(sample_mock(666, "devil"), is_equal_to(5));
-}
-
-typedef struct {
- double a;
- double b;
- const char *name;
-} LargerThanIntptr;
-
-static void out_param_mock(LargerThanIntptr* result) {
- mock(result);
-}
-
-
-Ensure(Mocks, can_stub_an_out_parameter) {
- LargerThanIntptr actual = { 3.14, 6.66, "bob" };
- LargerThanIntptr local = { 4.13, 7.89, "alice" };
-
- expect(out_param_mock,
- will_set_contents_of_parameter(result, &actual, sizeof(LargerThanIntptr))
- );
-
- out_param_mock(&local);
- assert_that_double(actual.a, is_equal_to_double(local.a));
- assert_that_double(actual.b, is_equal_to_double(local.b));
- assert_that(actual.name, is_equal_to_string(local.name));
- assert_that(&local, is_equal_to_contents_of(&actual, sizeof(LargerThanIntptr)));
-}
-
-Ensure(Mocks, learning_mocks_emit_none_when_learning_no_mocks) {
- cgreen_mocks_are(learning_mocks);
-}
-
-Ensure(Mocks, learning_mocks_emit_pastable_code) {
- cgreen_mocks_are(learning_mocks);
- string_out(1);
- string_out(2);
- integer_out();
- integer_out();
- string_out(3);
- integer_out();
-}
-
-/* It would be very nice it learning mocks could survive unexpected
- terminations but since the child process is already gone when the
- parent process detects this we need to either start catching
- exceptions in the child or communicate the learned mock calls to
- the parent some other way.
-
-Ensure(Mocks, learning_mocks_survive_termination) {
- cgreen_mocks_are(learning_mocks);
- string_out(1);
- *(int*)0 = 0;
-}
-*/
-
-/* Expected fail tests follow. */
-/* TODO: put these in a separate suite and validate all tests in said suite fail during 'make check' */
-/*
-Ensure(Mocks, can_declare_function_never_called) {
- never_expect(sample_mock);
-
- sample_mock(0,...
[truncated message content] |
|
From: <tho...@us...> - 2013-12-12 16:10:40
|
Revision: 538
http://sourceforge.net/p/cgreen/code/538
Author: thomasnilsson
Date: 2013-12-12 16:10:33 +0000 (Thu, 12 Dec 2013)
Log Message:
-----------
Added an alias for is_non_null
Modified Paths:
--------------
trunk/cgreen/include/cgreen/constraint_syntax_helpers.h
Modified: trunk/cgreen/include/cgreen/constraint_syntax_helpers.h
===================================================================
--- trunk/cgreen/include/cgreen/constraint_syntax_helpers.h 2013-12-07 10:33:14 UTC (rev 537)
+++ trunk/cgreen/include/cgreen/constraint_syntax_helpers.h 2013-12-12 16:10:33 UTC (rev 538)
@@ -46,6 +46,7 @@
*/
extern Constraint static_non_null_constraint;
extern Constraint *is_non_null;
+#define is_not_null (is_non_null)
extern Constraint static_null_constraint;
extern Constraint *is_null;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tho...@us...> - 2013-12-07 10:33:23
|
Revision: 537
http://sourceforge.net/p/cgreen/code/537
Author: thomasnilsson
Date: 2013-12-07 10:33:14 +0000 (Sat, 07 Dec 2013)
Log Message:
-----------
Added non-activated unit test for learning mocks to survive unexpected terminations (which I don't know how to approach, suggestions? ideas?)
Minor format cleanups
Modified Paths:
--------------
trunk/cgreen/src/mocks.c
trunk/cgreen/src/runner.c
trunk/cgreen/tests/mocks_tests.c
Modified: trunk/cgreen/src/mocks.c
===================================================================
--- trunk/cgreen/src/mocks.c 2013-12-03 07:32:49 UTC (rev 536)
+++ trunk/cgreen/src/mocks.c 2013-12-07 10:33:14 UTC (rev 537)
@@ -437,7 +437,7 @@
int e, c;
CgreenBreadcrumb *breadcrumb = get_test_reporter()->breadcrumb;
printf("%s: learned mocks:\n",
- get_current_from_breadcrumb(breadcrumb));
+ get_current_from_breadcrumb(breadcrumb));
if (cgreen_vector_size(learned_mock_calls) == 0) {
printf("\t<none>\n");
Modified: trunk/cgreen/src/runner.c
===================================================================
--- trunk/cgreen/src/runner.c 2013-12-03 07:32:49 UTC (rev 536)
+++ trunk/cgreen/src/runner.c 2013-12-07 10:33:14 UTC (rev 537)
@@ -56,7 +56,7 @@
static void run_every_test(TestSuite *suite, TestReporter *reporter) {
int i;
- run_specified_test_if_child(suite,reporter);
+ run_specified_test_if_child(suite, reporter);
(*reporter->start_suite)(reporter, suite->name, count_tests(suite));
for (i = 0; i < suite->size; i++) {
@@ -133,27 +133,27 @@
#ifdef __cplusplus
return;
} catch(const std::exception& exception) {
- message += '[';
- message += exception.what();
- message += ']';
+ message += '[';
+ message += exception.what();
+ message += ']';
} catch(const std::exception* exception) {
- message += '[';
- message += exception->what();
- message += ']';
+ message += '[';
+ message += exception->what();
+ message += ']';
} catch(const std::string& exception_message) {
- message += '[';
- message += exception_message;
- message += ']';
+ message += '[';
+ message += exception_message;
+ message += ']';
} catch(const std::string *exception_message) {
- message += '[';
- message += *exception_message;
- message += ']';
+ message += '[';
+ message += *exception_message;
+ message += ']';
} catch(const char *exception_message) {
- message += '[';
- message += exception_message;
- message += ']';
+ message += '[';
+ message += exception_message;
+ message += ']';
} catch (...) {
- message += "unknown exception type";
+ message += "unknown exception type";
}
va_list no_arguments;
memset(&no_arguments, 0, sizeof(va_list));
@@ -172,27 +172,27 @@
#ifdef __cplusplus
return;
} catch(const std::exception& exception) {
- message += '[';
- message += exception.what();
- message += ']';
+ message += '[';
+ message += exception.what();
+ message += ']';
} catch(const std::exception* exception) {
- message += '[';
- message += exception->what();
- message += ']';
+ message += '[';
+ message += exception->what();
+ message += ']';
} catch(const std::string& exception_message) {
- message += '[';
- message += exception_message;
- message += ']';
+ message += '[';
+ message += exception_message;
+ message += ']';
} catch(const std::string *exception_message) {
- message += '[';
- message += *exception_message;
- message += ']';
+ message += '[';
+ message += *exception_message;
+ message += ']';
} catch(const char *exception_message) {
- message += '[';
- message += exception_message;
- message += ']';
+ message += '[';
+ message += exception_message;
+ message += ']';
} catch (...) {
- message += "unknown exception type";
+ message += "unknown exception type";
}
va_list no_arguments;
memset(&no_arguments, 0, sizeof(va_list));
@@ -218,27 +218,27 @@
#ifdef __cplusplus
return;
} catch(const std::exception& exception) {
- message += '[';
- message += exception.what();
- message += ']';
+ message += '[';
+ message += exception.what();
+ message += ']';
} catch(const std::exception* exception) {
- message += '[';
- message += exception->what();
- message += ']';
+ message += '[';
+ message += exception->what();
+ message += ']';
} catch(const std::string& exception_message) {
- message += '[';
- message += exception_message;
- message += ']';
+ message += '[';
+ message += exception_message;
+ message += ']';
} catch(const std::string *exception_message) {
- message += '[';
- message += *exception_message;
- message += ']';
+ message += '[';
+ message += *exception_message;
+ message += ']';
} catch(const char *exception_message) {
- message += '[';
- message += exception_message;
- message += ']';
+ message += '[';
+ message += exception_message;
+ message += ']';
} catch (...) {
- message += "unknown exception type";
+ message += "unknown exception type";
}
va_list no_arguments;
memset(&no_arguments, 0, sizeof(va_list));
@@ -268,7 +268,6 @@
}
run(spec);
-
// for historical reasons the suite can have a teardown
if (suite->teardown != &do_nothing) {
(*suite->teardown)();
Modified: trunk/cgreen/tests/mocks_tests.c
===================================================================
--- trunk/cgreen/tests/mocks_tests.c 2013-12-03 07:32:49 UTC (rev 536)
+++ trunk/cgreen/tests/mocks_tests.c 2013-12-07 10:33:14 UTC (rev 537)
@@ -8,16 +8,20 @@
using namespace cgreen;
#endif
+Describe(Mocks);
+BeforeEach(Mocks) {}
+AfterEach(Mocks) {}
+
static int integer_out() {
return (int)mock();
}
-Ensure(default_return_value_when_no_presets_for_loose_mock) {
+Ensure(Mocks, default_return_value_when_no_presets_for_loose_mock) {
cgreen_mocks_are(loose_mocks);
assert_that(integer_out(), is_equal_to(0));
}
-Ensure(can_stub_an_integer_return) {
+Ensure(Mocks, can_stub_an_integer_return) {
expect(integer_out,
will_return(3)
);
@@ -25,7 +29,7 @@
assert_that(integer_out(), is_equal_to(3));
}
-Ensure(repeats_return_value_when_set_to_always) {
+Ensure(Mocks, repeats_return_value_when_set_to_always) {
always_expect(integer_out,
will_return(3)
);
@@ -34,7 +38,7 @@
assert_that(integer_out(), is_equal_to(3));
}
-Ensure(can_stub_an_integer_return_sequence) {
+Ensure(Mocks, can_stub_an_integer_return_sequence) {
expect(integer_out,
will_return(1)
);
@@ -52,7 +56,7 @@
assert_that(integer_out(), is_equal_to(3));
}
-Ensure(expectations_are_reset_between_tests_with_loose_mocks) {
+Ensure(Mocks, expectations_are_reset_between_tests_with_loose_mocks) {
cgreen_mocks_are(loose_mocks);
assert_that(integer_out(), is_equal_to(0));
}
@@ -61,12 +65,12 @@
return (char *)mock(p1);
}
-Ensure(can_stub_a_string_return) {
+Ensure(Mocks, can_stub_a_string_return) {
expect(string_out, will_return("hello"));
assert_string_equal(string_out(1), "hello");
}
-Ensure(can_stub_a_string_sequence) {
+Ensure(Mocks, can_stub_a_string_sequence) {
expect(string_out, will_return("hello"));
expect(string_out, will_return("goodbye"));
@@ -78,24 +82,24 @@
mock(i);
}
-Ensure(expecting_once_with_any_parameters) {
+Ensure(Mocks, expecting_once_with_any_parameters) {
expect(integer_in);
integer_in(3);
}
-Ensure(expecting_once_with_parameter_checks_that_parameter) {
+Ensure(Mocks, expecting_once_with_parameter_checks_that_parameter) {
expect(integer_in, when(i, is_equal_to(3)));
integer_in(3);
}
-Ensure(always_expect_keeps_affirming_parameter) {
+Ensure(Mocks, always_expect_keeps_affirming_parameter) {
always_expect(integer_in, when(i, is_equal_to(3)));
integer_in(3);
integer_in(3);
integer_in(3);
}
-Ensure(expect_a_sequence) {
+Ensure(Mocks, expect_a_sequence) {
expect(integer_in, when(i, is_equal_to(1)));
expect(integer_in, when(i, is_equal_to(2)));
expect(integer_in, when(i, is_equal_to(3)));
@@ -108,29 +112,29 @@
mock(s);
}
-Ensure(string_expect_is_confirmed) {
+Ensure(Mocks, string_expect_is_confirmed) {
expect(string_in, when(s, is_equal_to_string("hello")));
string_in("hello");
}
-Ensure(string_contains_expectation_is_confirmed) {
+Ensure(Mocks, string_contains_expectation_is_confirmed) {
expect(string_in, when(s, contains_string("hello")));
string_in("alice, hello");
}
-Ensure(string_expect_is_confirmed_even_when_null) {
+Ensure(Mocks, string_expect_is_confirmed_even_when_null) {
expect(string_in, when(s, is_equal_to_string((char *)NULL)));
string_in(NULL);
}
-Ensure(string_expect_sequence) {
+Ensure(Mocks, string_expect_sequence) {
expect(string_in, when(s, is_equal_to_string("hello")));
expect(string_in, when(s, is_equal_to_string("goodbye")));
string_in("hello");
string_in("goodbye");
}
-Ensure(expecting_once_with_non_null_parameter_checks_that_parameter) {
+Ensure(Mocks, expecting_once_with_non_null_parameter_checks_that_parameter) {
expect(string_in, when(s, is_non_null));
string_in("anything");
}
@@ -139,12 +143,12 @@
mock(box_double(d));
}
-Ensure(double_expect_is_confirmed) {
+Ensure(Mocks, double_expect_is_confirmed) {
expect(double_in, when(d, is_equal_to_double(3.14)));
double_in(3.14);
}
-Ensure(double_expect_sequence) {
+Ensure(Mocks, double_expect_sequence) {
expect(double_in, when(d, is_equal_to_double(1.0)));
expect(double_in, when(d, is_equal_to_double(2.0)));
double_in(1.0);
@@ -155,7 +159,7 @@
mock(i, s);
}
-Ensure(confirming_multiple_parameters_multiple_times) {
+Ensure(Mocks, confirming_multiple_parameters_multiple_times) {
expect(mixed_parameters,
when(i, is_equal_to(1)),
when(s, is_equal_to_string("Hello"))
@@ -173,7 +177,7 @@
return (int)mock(i, s);
}
-Ensure(can_mock_full_function_call) {
+Ensure(Mocks, can_mock_full_function_call) {
expect(sample_mock,
will_return(5),
when(i, is_equal_to(666)),
@@ -183,7 +187,7 @@
assert_that(sample_mock(666, "devil"), is_equal_to(5));
}
-Ensure(when_called_with_always_should_not_tally_counts) {
+Ensure(Mocks, when_called_with_always_should_not_tally_counts) {
always_expect(string_out,
will_return(5),
when(i, is_equal_to(666)),
@@ -191,7 +195,7 @@
);
}
-Ensure(can_mock_full_sequence) {
+Ensure(Mocks, can_mock_full_sequence) {
expect(sample_mock,
will_return(5),
when(i, is_equal_to(666)),
@@ -208,7 +212,7 @@
assert_that(sample_mock(667, "beastie"), is_equal_to(6));
}
-Ensure(can_always_mock_full_function_call) {
+Ensure(Mocks, can_always_mock_full_function_call) {
always_expect(sample_mock,
will_return(5),
when(i, is_equal_to(666)),
@@ -231,7 +235,7 @@
}
-Ensure(can_stub_an_out_parameter) {
+Ensure(Mocks, can_stub_an_out_parameter) {
LargerThanIntptr actual = { 3.14, 6.66, "bob" };
LargerThanIntptr local = { 4.13, 7.89, "alice" };
@@ -246,11 +250,11 @@
assert_that(&local, is_equal_to_contents_of(&actual, sizeof(LargerThanIntptr)));
}
-Ensure(none_emitted_when_learning_no_mocks) {
+Ensure(Mocks, learning_mocks_emit_none_when_learning_no_mocks) {
cgreen_mocks_are(learning_mocks);
}
-Ensure(pastable_code_emitted_by_learning_mocks) {
+Ensure(Mocks, learning_mocks_emit_pastable_code) {
cgreen_mocks_are(learning_mocks);
string_out(1);
string_out(2);
@@ -260,16 +264,29 @@
integer_out();
}
+/* It would be very nice it learning mocks could survive unexpected
+ terminations but since the child process is already gone when the
+ parent process detects this we need to either start catching
+ exceptions in the child or communicate the learned mock calls to
+ the parent some other way.
+
+Ensure(Mocks, learning_mocks_survive_termination) {
+ cgreen_mocks_are(learning_mocks);
+ string_out(1);
+ *(int*)0 = 0;
+}
+*/
+
/* Expected fail tests follow. */
/* TODO: put these in a separate suite and validate all tests in said suite fail during 'make check' */
/*
-Ensure(can_declare_function_never_called) {
+Ensure(Mocks, can_declare_function_never_called) {
never_expect(sample_mock);
sample_mock(0, "");
}
-Ensure(calls_beyond_expected_sequence_fail_when_mocks_are_strict) {
+Ensure(Mocks, calls_beyond_expected_sequence_fail_when_mocks_are_strict) {
expect(integer_out,
will_return(1)
);
@@ -289,17 +306,17 @@
assert_that(integer_out(), is_equal_to(3));
}
-Ensure(failure_when_no_presets_for_default_strict_mock) {
+Ensure(Mocks, failure_when_no_presets_for_default_strict_mock) {
assert_that(integer_out(), is_equal_to(0));
}
-Ensure(failure_reported_when_expect_after_never_expect_for_same_function) {
+Ensure(Mocks, failure_reported_when_expect_after_never_expect_for_same_function) {
never_expect(integer_out);
expect(integer_out);
}
-Ensure(failure_reported_when_expect_after_always_expect_for_same_function) {
+Ensure(Mocks, failure_reported_when_expect_after_always_expect_for_same_function) {
always_expect(integer_out,
will_return(666)
);
@@ -307,7 +324,7 @@
expect(integer_out);
}
-Ensure(single_uncalled_expectation_fails_tally) {
+Ensure(Mocks, single_uncalled_expectation_fails_tally) {
expect(string_out,
will_return(5),
when(i, is_equal_to(666)),
@@ -318,40 +335,41 @@
TestSuite *mock_tests() {
TestSuite *suite = create_test_suite();
- add_test(suite, none_emitted_when_learning_no_mocks);
- add_test(suite, pastable_code_emitted_by_learning_mocks);
- add_test(suite, default_return_value_when_no_presets_for_loose_mock);
- add_test(suite, can_stub_an_integer_return);
- add_test(suite, repeats_return_value_when_set_to_always);
- add_test(suite, can_stub_an_integer_return_sequence);
- add_test(suite, expectations_are_reset_between_tests_with_loose_mocks);
- add_test(suite, can_stub_a_string_return);
- add_test(suite, can_stub_a_string_sequence);
- add_test(suite, expecting_once_with_any_parameters);
- add_test(suite, expecting_once_with_parameter_checks_that_parameter);
- add_test(suite, always_expect_keeps_affirming_parameter);
- add_test(suite, expect_a_sequence);
- add_test(suite, string_expect_is_confirmed);
- add_test(suite, string_expect_is_confirmed_even_when_null);
- add_test(suite, string_expect_sequence);
- add_test(suite, expecting_once_with_non_null_parameter_checks_that_parameter);
- add_test(suite, double_expect_is_confirmed);
- add_test(suite, double_expect_sequence);
- add_test(suite, confirming_multiple_parameters_multiple_times);
- add_test(suite, can_mock_full_function_call);
- add_test(suite, when_called_with_always_should_not_tally_counts);
- add_test(suite, can_mock_full_sequence);
- add_test(suite, can_always_mock_full_function_call);
- add_test(suite, can_stub_an_out_parameter);
- add_test(suite, string_contains_expectation_is_confirmed);
+ add_test_with_context(suite, Mocks, learning_mocks_emit_none_when_learning_no_mocks);
+ add_test_with_context(suite, Mocks, learning_mocks_emit_pastable_code);
+ // add_test_with_context(suite, Mocks, learning_mocks_survive_termination);
+ add_test_with_context(suite, Mocks, default_return_value_when_no_presets_for_loose_mock);
+ add_test_with_context(suite, Mocks, can_stub_an_integer_return);
+ add_test_with_context(suite, Mocks, repeats_return_value_when_set_to_always);
+ add_test_with_context(suite, Mocks, can_stub_an_integer_return_sequence);
+ add_test_with_context(suite, Mocks, expectations_are_reset_between_tests_with_loose_mocks);
+ add_test_with_context(suite, Mocks, can_stub_a_string_return);
+ add_test_with_context(suite, Mocks, can_stub_a_string_sequence);
+ add_test_with_context(suite, Mocks, expecting_once_with_any_parameters);
+ add_test_with_context(suite, Mocks, expecting_once_with_parameter_checks_that_parameter);
+ add_test_with_context(suite, Mocks, always_expect_keeps_affirming_parameter);
+ add_test_with_context(suite, Mocks, expect_a_sequence);
+ add_test_with_context(suite, Mocks, string_expect_is_confirmed);
+ add_test_with_context(suite, Mocks, string_expect_is_confirmed_even_when_null);
+ add_test_with_context(suite, Mocks, string_expect_sequence);
+ add_test_with_context(suite, Mocks, expecting_once_with_non_null_parameter_checks_that_parameter);
+ add_test_with_context(suite, Mocks, double_expect_is_confirmed);
+ add_test_with_context(suite, Mocks, double_expect_sequence);
+ add_test_with_context(suite, Mocks, confirming_multiple_parameters_multiple_times);
+ add_test_with_context(suite, Mocks, can_mock_full_function_call);
+ add_test_with_context(suite, Mocks, when_called_with_always_should_not_tally_counts);
+ add_test_with_context(suite, Mocks, can_mock_full_sequence);
+ add_test_with_context(suite, Mocks, can_always_mock_full_function_call);
+ add_test_with_context(suite, Mocks, can_stub_an_out_parameter);
+ add_test_with_context(suite, Mocks, string_contains_expectation_is_confirmed);
/* expected failures. TODO: put these in a separate suite, as per comments above. */
-/* add_test(suite, failure_reported_when_expect_after_always_expect_for_same_function);
- add_test(suite, single_uncalled_expectation_fails_tally);
- add_test(suite, can_declare_function_never_called);
- add_test(suite, failure_reported_when_expect_after_never_expect_for_same_function);
- add_test(suite, failure_when_no_presets_for_default_strict_mock);
- add_test(suite, calls_beyond_expected_sequence_fail_when_mocks_are_strict);
+/* add_test_with_context(suite, Mocks, failure_reported_when_expect_after_always_expect_for_same_function);
+ add_test_with_context(suite, Mocks, single_uncalled_expectation_fails_tally);
+ add_test_with_context(suite, Mocks, can_declare_function_never_called);
+ add_test_with_context(suite, Mocks, failure_reported_when_expect_after_never_expect_for_same_function);
+ add_test_with_context(suite, Mocks, failure_when_no_presets_for_default_strict_mock);
+ add_test_with_context(suite, Mocks, calls_beyond_expected_sequence_fail_when_mocks_are_strict);
*/
return suite;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tho...@us...> - 2013-12-03 07:32:57
|
Revision: 536
http://sourceforge.net/p/cgreen/code/536
Author: thomasnilsson
Date: 2013-12-03 07:32:49 +0000 (Tue, 03 Dec 2013)
Log Message:
-----------
Only do dlclose if it was open, otherwise crash
Modified Paths:
--------------
trunk/cgreen/tools/runner.c
Modified: trunk/cgreen/tools/runner.c
===================================================================
--- trunk/cgreen/tools/runner.c 2013-11-27 15:42:12 UTC (rev 535)
+++ trunk/cgreen/tools/runner.c 2013-12-03 07:32:49 UTC (rev 536)
@@ -370,16 +370,16 @@
printf("Discovered %d test(s)\n", count(discovered_tests));
if (!dont_run) {
- if (verbose)
- printf("Opening [%s]", test_library_name);
- test_library_handle = dlopen(test_library_name, RTLD_NOW);
- if (test_library_handle == NULL) {
- fprintf (stderr, "\nERROR: dlopen failure (error: %s)\n", dlerror());
- status = 2;
- } else {
- status = run_tests(reporter, suite_name, test_name, test_library_handle, discovered_tests, verbose);
- }
- dlclose(test_library_handle);
+ if (verbose)
+ printf("Opening [%s]", test_library_name);
+ test_library_handle = dlopen(test_library_name, RTLD_NOW);
+ if (test_library_handle == NULL) {
+ fprintf (stderr, "\nERROR: dlopen failure (error: %s)\n", dlerror());
+ status = 2;
+ } else {
+ status = run_tests(reporter, suite_name, test_name, test_library_handle, discovered_tests, verbose);
+ dlclose(test_library_handle);
+ }
}
reflective_runner_cleanup(discovered_tests);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <las...@us...> - 2013-11-27 15:42:22
|
Revision: 535
http://sourceforge.net/p/cgreen/code/535
Author: lastcraft
Date: 2013-11-27 15:42:12 +0000 (Wed, 27 Nov 2013)
Log Message:
-----------
Mac OSX 10.9 doesn't seem to zero the wait status when returning from wait(3)
Modified Paths:
--------------
trunk/cgreen/src/posix_runner_platform.c
Modified: trunk/cgreen/src/posix_runner_platform.c
===================================================================
--- trunk/cgreen/src/posix_runner_platform.c 2013-11-19 22:11:41 UTC (rev 534)
+++ trunk/cgreen/src/posix_runner_platform.c 2013-11-27 15:42:12 UTC (rev 535)
@@ -56,7 +56,7 @@
}
static int wait_for_child_process() {
- int status;
+ int status = 0;
ignore_ctrl_c();
wait(&status);
allow_ctrl_c();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|