From d37f46ffbda0172ae5ae7eb87c49c158cbad95be Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Wed, 24 Jun 2009 12:09:43 +0000 Subject: [PATCH] - updated tests (unit and system) to prove strict ordering is happy git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@136 bf332499-1b4d-0410-844d-d2d48d5cc64c --- rakefile_helper.rb | 3 +++ .../enforce_strict_ordering.yml | 5 ++++- test/unit/cmock_generator_main_test.rb | 6 ++++++ .../unit/cmock_generator_plugin_expect_test.rb | 18 ++++++++++++++---- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/rakefile_helper.rb b/rakefile_helper.rb index 3f53653..4e9b90f 100644 --- a/rakefile_helper.rb +++ b/rakefile_helper.rb @@ -250,6 +250,9 @@ module RakefileHelpers total_failures += 1 test_results =~ /test#{index+1}:(.+)/ failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:#{$1}" + elsif (test[:verify_error]) and not (test_results =~ /test#{index+1}:.*#{test[:verify_error]}/) + total_failures += 1 + failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:should have output matching '#{test[:verify_error]}'" end end end diff --git a/test/system/test_interactions/enforce_strict_ordering.yml b/test/system/test_interactions/enforce_strict_ordering.yml index 3a46ec8..ed48a1e 100644 --- a/test/system/test_interactions/enforce_strict_ordering.yml +++ b/test/system/test_interactions/enforce_strict_ordering.yml @@ -89,7 +89,8 @@ } - :pass: FALSE - :should: 'fail because bar() is not called but is expected' + :should: 'fail because bar() is called but is not expected' + :verify_error: 'Called More Times Than Expected' :code: | test() { @@ -99,6 +100,7 @@ - :pass: FALSE :should: 'fail because bar() is called twice but is expected once' + :verify_error: 'called unexpected number of times' :code: | test() { @@ -110,6 +112,7 @@ - :pass: FALSE :should: 'fail because bar and foo called in reverse order' + :verify_error: 'Called Out Of Order' :code: | test() { diff --git a/test/unit/cmock_generator_main_test.rb b/test/unit/cmock_generator_main_test.rb index bc90099..e15673a 100644 --- a/test/unit/cmock_generator_main_test.rb +++ b/test/unit/cmock_generator_main_test.rb @@ -195,6 +195,7 @@ class CMockGeneratorTest < Test::Unit::TestCase expected = [ "extern jmp_buf AbortFrame;\n", "extern int GlobalExpectCount;\n", "extern int GlobalVerifyOrder;\n", + "extern char* GlobalOrderError;\n", "\n" ] @cmock_generator_strict.create_extern_declarations(output) @@ -297,6 +298,11 @@ class CMockGeneratorTest < Test::Unit::TestCase " memset(&Mock, 0, sizeof(Mock));\n", " GlobalExpectCount = 0;\n", " GlobalVerifyOrder = 0;\n", + " if (GlobalOrderError)\n", + " {\n", + " free(GlobalOrderError);\n", + " GlobalOrderError = NULL;\n", + " }\n", "}\n\n" ] @plugins.expect.run(:mock_destroy, functions[0]).returns([" Uno_First(int Candy, int)"," Dos_First(int Candy, int)"]) diff --git a/test/unit/cmock_generator_plugin_expect_test.rb b/test/unit/cmock_generator_plugin_expect_test.rb index a1aaecf..fa5f534 100644 --- a/test/unit/cmock_generator_plugin_expect_test.rb +++ b/test/unit/cmock_generator_plugin_expect_test.rb @@ -172,7 +172,6 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase end should "add mock function implementation using ordering if needed" do - @utils.expect.expect_helper('int','*p_expected','GlobalVerifyOrder',"\"Function 'Apple' Called Out Of Order.\"", ' ').returns(" mocked_retval") function = {:name => "Apple", :args => [], :return_type => "void"} expected = [" Mock.Apple_CallCount++;\n", " if (Mock.Apple_CallCount > Mock.Apple_CallsExpected)\n", @@ -184,7 +183,13 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase " ++GlobalVerifyOrder;\n", " if (Mock.Apple_CallOrder != Mock.Apple_CallOrder_Tail)\n", " Mock.Apple_CallOrder++;\n", - " mocked_retval", + " if ((*p_expected != GlobalVerifyOrder) && (GlobalOrderError == NULL))\n", + " {\n", + " const char* ErrStr = \"Function 'Apple' Called Out Of Order.\";\n", + " GlobalOrderError = malloc(38);\n", + " if (GlobalOrderError)\n", + " strcpy(GlobalOrderError, ErrStr);\n", + " }\n", " }\n" ] @cmock_generator_plugin_expect.ordered = true @@ -204,10 +209,15 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase " ++GlobalVerifyOrder;\n", " if (Mock.Apple_CallOrder != Mock.Apple_CallOrder_Tail)\n", " Mock.Apple_CallOrder++;\n", - " BLEH", + " if ((*p_expected != GlobalVerifyOrder) && (GlobalOrderError == NULL))\n", + " {\n", + " const char* ErrStr = \"Function 'Apple' Called Out Of Order.\";\n", + " GlobalOrderError = malloc(38);\n", + " if (GlobalOrderError)\n", + " strcpy(GlobalOrderError, ErrStr);\n", + " }\n", " }\n" ] - @utils.expect.expect_helper('int', '*p_expected', 'GlobalVerifyOrder', "\"Function 'Apple' Called Out Of Order.\""," ").returns(" BLEH") returned = @cmock_generator_plugin_expect_strict.mock_implementation(function) assert_equal(expected, returned) end