diff --git a/SampleProjects/DoSomething/do-something.cpp b/SampleProjects/DoSomething/do-something.cpp index 8f5e178b..d063be0d 100644 --- a/SampleProjects/DoSomething/do-something.cpp +++ b/SampleProjects/DoSomething/do-something.cpp @@ -4,3 +4,19 @@ int doSomething(void) { millis(); // this line is only here to test that we're able to refer to the builtins return 4; }; + +static const struct something table[] = { + { 1, "abc" }, + { 2, "xyz" }, + { 4, "123" }, +}; + +const struct something *findSomething(int id) { + for (unsigned int i = 0; i < 3; i++) { + if (table[i].id == id) { + return &table[i]; + } + } + return nullptr; +} + diff --git a/SampleProjects/DoSomething/do-something.h b/SampleProjects/DoSomething/do-something.h index 13322823..dc915057 100644 --- a/SampleProjects/DoSomething/do-something.h +++ b/SampleProjects/DoSomething/do-something.h @@ -1,3 +1,11 @@ #pragma once #include int doSomething(void); + +struct something { + int id; + const char *text; +}; + +const struct something *findSomething(int id); + diff --git a/SampleProjects/DoSomething/test/README.md b/SampleProjects/DoSomething/test/README.md new file mode 100644 index 00000000..9d2112b7 --- /dev/null +++ b/SampleProjects/DoSomething/test/README.md @@ -0,0 +1,3 @@ +# Naming convention # + +Files in this directory is expected to have names that either contains "bad" if it is expected to fail or "good" if it is expected to pass. diff --git a/SampleProjects/DoSomething/test/good-find-something.cpp b/SampleProjects/DoSomething/test/good-find-something.cpp new file mode 100644 index 00000000..5cbeea67 --- /dev/null +++ b/SampleProjects/DoSomething/test/good-find-something.cpp @@ -0,0 +1,21 @@ +#include + +#include "do-something.h" + +unittest(find_something_that_exists) +{ + const struct something *result; + result = findSomething(1); + assertNotNull(result); + assertEqual("abc", result->text); +} + +unittest(find_something_that_does_not_exists) +{ + const struct something *result; + result = findSomething(1000); + assertNull(result); +} + +unittest_main() + diff --git a/spec/cpp_library_spec.rb b/spec/cpp_library_spec.rb index 8044486a..7fdec6b8 100644 --- a/spec/cpp_library_spec.rb +++ b/spec/cpp_library_spec.rb @@ -45,6 +45,7 @@ def get_relative_dir(sampleprojects_tests_dir) dosomething_test_files = [ "DoSomething/test/good-null.cpp", "DoSomething/test/good-library.cpp", + "DoSomething/test/good-find-something.cpp", "DoSomething/test/bad-null.cpp", ].map { |f| Pathname.new(f) } relative_paths = cpp_library.test_files.map { |f| get_relative_dir(f) }