From 27d10a5197872c3a42d16778433b3a31dc58bc8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20L=C3=B8vdal?= Date: Sun, 3 Feb 2019 21:49:30 +0100 Subject: [PATCH 1/3] Add findSomething function --- SampleProjects/DoSomething/do-something.cpp | 16 ++++++++++++++++ SampleProjects/DoSomething/do-something.h | 8 ++++++++ 2 files changed, 24 insertions(+) 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); + From bd46dc66f3c86b6e0be8f125970a6d5c761e9818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20L=C3=B8vdal?= Date: Sun, 3 Feb 2019 21:57:23 +0100 Subject: [PATCH 2/3] Add test that used to fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In file included from /usr/include/stdio.h:33, from /usr/include/c++/8/cstdio:42, from /usr/include/c++/8/ext/string_conversions.h:43, from /usr/include/c++/8/bits/basic_string.h:6400, from /usr/include/c++/8/string:52, from /usr/include/c++/8/stdexcept:39, from .../arduino_ci/cpp/arduino/WString.h:4, from .../arduino_ci/cpp/arduino/Arduino.h:13, from .../arduino_ci/SampleProjects/DoSomething/do-something.cpp:1: .../arduino_ci/SampleProjects/DoSomething/do-something.cpp: In function ‘const something* findSomething(int)’: .../arduino_ci/cpp/arduino/Nullptr.h:5:31: error: invalid conversion from ‘my_nullptr_t’ {aka ‘void*’} to ‘const something*’ [-fpermissive] #define nullptr (my_nullptr_t)NULL ^~~~ .../arduino_ci/SampleProjects/DoSomething/do-something.cpp:20:9: note: in expansion of macro ‘nullptr’ return nullptr; ^~~~~~~ --- .../DoSomething/test/good-find-something.cpp | 21 +++++++++++++++++++ spec/cpp_library_spec.rb | 1 + 2 files changed, 22 insertions(+) create mode 100644 SampleProjects/DoSomething/test/good-find-something.cpp 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) } From 26c1c4a1e16a5518f42ac8d4744ce676793a9c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20L=C3=B8vdal?= Date: Wed, 6 Feb 2019 00:25:18 +0100 Subject: [PATCH 3/3] Add SampleProjects/DoSomething/test/README.md --- SampleProjects/DoSomething/test/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 SampleProjects/DoSomething/test/README.md 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.