arduino_ci 0.3.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +125 -69
  3. data/REFERENCE.md +711 -0
  4. data/cpp/arduino/Arduino.h +1 -7
  5. data/cpp/arduino/ArduinoDefines.h +3 -0
  6. data/cpp/arduino/AvrMath.h +117 -17
  7. data/cpp/arduino/Client.h +27 -0
  8. data/cpp/arduino/EEPROM.h +64 -0
  9. data/cpp/arduino/Godmode.cpp +7 -0
  10. data/cpp/arduino/Godmode.h +121 -15
  11. data/cpp/arduino/HardwareSerial.h +4 -4
  12. data/cpp/arduino/IPAddress.h +59 -0
  13. data/cpp/arduino/Print.h +9 -12
  14. data/cpp/arduino/Printable.h +8 -0
  15. data/cpp/arduino/SPI.h +11 -3
  16. data/cpp/arduino/Server.h +5 -0
  17. data/cpp/arduino/Udp.h +27 -0
  18. data/cpp/arduino/Wire.h +197 -77
  19. data/cpp/arduino/avr/io.h +10 -1
  20. data/cpp/arduino/avr/pgmspace.h +76 -46
  21. data/cpp/unittest/ArduinoUnitTests.h +32 -0
  22. data/cpp/unittest/Assertion.h +54 -26
  23. data/cpp/unittest/Compare.h +58 -51
  24. data/cpp/unittest/OstreamHelpers.h +4 -0
  25. data/exe/arduino_ci.rb +538 -0
  26. data/exe/arduino_ci_remote.rb +2 -393
  27. data/exe/arduino_library_location.rb +2 -2
  28. data/exe/ensure_arduino_installation.rb +7 -1
  29. data/lib/arduino_ci.rb +1 -0
  30. data/lib/arduino_ci/arduino_backend.rb +238 -0
  31. data/lib/arduino_ci/arduino_downloader.rb +43 -73
  32. data/lib/arduino_ci/arduino_downloader_linux.rb +17 -55
  33. data/lib/arduino_ci/arduino_downloader_osx.rb +21 -33
  34. data/lib/arduino_ci/arduino_downloader_windows.rb +11 -53
  35. data/lib/arduino_ci/arduino_installation.rb +18 -80
  36. data/lib/arduino_ci/ci_config.rb +8 -11
  37. data/lib/arduino_ci/cpp_library.rb +250 -59
  38. data/lib/arduino_ci/host.rb +59 -4
  39. data/lib/arduino_ci/library_properties.rb +101 -0
  40. data/lib/arduino_ci/version.rb +1 -1
  41. data/misc/default.yml +57 -6
  42. metadata +19 -87
  43. data/cpp/arduino/Arduino.h.orig +0 -143
  44. data/exe/libasan.rb +0 -29
  45. data/lib/arduino_ci/arduino_cmd.rb +0 -332
  46. data/lib/arduino_ci/arduino_cmd_linux.rb +0 -17
  47. data/lib/arduino_ci/arduino_cmd_linux_builder.rb +0 -19
  48. data/lib/arduino_ci/arduino_cmd_osx.rb +0 -17
  49. data/lib/arduino_ci/arduino_cmd_windows.rb +0 -17
@@ -96,7 +96,16 @@
96
96
  #ifndef _AVR_IO_H_
97
97
  #define _AVR_IO_H_
98
98
 
99
- #define _SFR_IO8(io_addr) (io_addr) // this macro is all we need from the sfr file
99
+ #include <stdint.h>
100
+
101
+ // hardware mocks
102
+ // this set of macros is all we need from the sfr file
103
+ extern volatile uint8_t __ARDUINO_CI_SFR_MOCK[1024];
104
+ #define _SFR_IO8(io_addr) (*(volatile uint8_t *)(__ARDUINO_CI_SFR_MOCK + io_addr))
105
+ #define _SFR_IO16(io_addr) (*(volatile uint16_t *)(__ARDUINO_CI_SFR_MOCK + io_addr))
106
+ #define _SFR_MEM8(io_addr) (*(volatile uint8_t *)(__ARDUINO_CI_SFR_MOCK + io_addr))
107
+ #define _SFR_MEM16(io_addr) (*(volatile uint16_t *)(__ARDUINO_CI_SFR_MOCK + io_addr))
108
+ #define _SFR_MEM32(io_addr) (*(volatile uint32_t *)(__ARDUINO_CI_SFR_MOCK + io_addr))
100
109
 
101
110
  #if defined (__AVR_AT94K__)
102
111
  # include "ioat94k.h"
@@ -14,8 +14,10 @@ out = externs.map {|l| l.split("(")[0].split(" ")[-1].gsub("*", "") }.uniq
14
14
  out.each { |l| puts d(l) }
15
15
  */
16
16
 
17
- #include <avr/io.h>
18
17
  #include <string.h>
18
+ #include <stdio.h>
19
+ #include <stdint.h>
20
+ #include <stdarg.h>
19
21
 
20
22
  #define PROGMEM
21
23
 
@@ -27,6 +29,11 @@ out.each { |l| puts d(l) }
27
29
  #define PGM_VOID_P const void *
28
30
  #endif
29
31
 
32
+ // These are normally 32-bit, but here use (u)intptr_t to ensure a pointer can
33
+ // always be safely cast to these types.
34
+ typedef intptr_t int_farptr_t;
35
+ typedef uintptr_t uint_farptr_t;
36
+
30
37
  // everything's a no-op
31
38
  #define PSTR(s) ((const char *)(s))
32
39
 
@@ -34,13 +41,13 @@ out.each { |l| puts d(l) }
34
41
  #define pgm_read_word_near(address_short) (* (const uint16_t *) (address_short) )
35
42
  #define pgm_read_dword_near(address_short) (* (const uint32_t *) (address_short) )
36
43
  #define pgm_read_float_near(address_short) (* (const float *) (address_short) )
37
- #define pgm_read_ptr_near(address_short) (* (const void *) (address_short) )
44
+ #define pgm_read_ptr_near(address_short) (* (const void **) (address_short) )
38
45
 
39
46
  #define pgm_read_byte_far(address_long) (* (const uint8_t *) (address_long) )
40
47
  #define pgm_read_word_far(address_long) (* (const uint16_t *) (address_long) )
41
48
  #define pgm_read_dword_far(address_long) (* (const uint32_t *) (address_long) )
42
49
  #define pgm_read_float_far(address_long) (* (const float *) (address_long) )
43
- #define pgm_read_ptr_far(address_long) (* (const void *) (address_long) )
50
+ #define pgm_read_ptr_far(address_long) (* (const void **) (address_long) )
44
51
 
45
52
  #define pgm_read_byte(address_short) pgm_read_byte_near(address_short)
46
53
  #define pgm_read_word(address_short) pgm_read_word_near(address_short)
@@ -50,46 +57,69 @@ out.each { |l| puts d(l) }
50
57
 
51
58
  #define pgm_get_far_address(var) ( (uint_farptr_t) (&(var)) )
52
59
 
53
- #define memchr_P(...) ::memchr(__VA_ARGS__)
54
- #define memcmp_P(...) ::memcmp(__VA_ARGS__)
55
- #define memccpy_P(...) ::memccpy(__VA_ARGS__)
56
- #define memcpy_P(...) ::memcpy(__VA_ARGS__)
57
- #define memmem_P(...) ::memmem(__VA_ARGS__)
58
- #define memrchr_P(...) ::memrchr(__VA_ARGS__)
59
- #define strcat_P(...) ::strcat(__VA_ARGS__)
60
- #define strchr_P(...) ::strchr(__VA_ARGS__)
61
- #define strchrnul_P(...) ::strchrnul(__VA_ARGS__)
62
- #define strcmp_P(...) ::strcmp(__VA_ARGS__)
63
- #define strcpy_P(...) ::strcpy(__VA_ARGS__)
64
- #define strcasecmp_P(...) ::strcasecmp(__VA_ARGS__)
65
- #define strcasestr_P(...) ::strcasestr(__VA_ARGS__)
66
- #define strcspn_P(...) ::strcspn(__VA_ARGS__)
67
- #define strlcat_P(...) ::strlcat(__VA_ARGS__)
68
- #define strlcpy_P(...) ::strlcpy(__VA_ARGS__)
69
- #define strnlen_P(...) ::strnlen(__VA_ARGS__)
70
- #define strncmp_P(...) ::strncmp(__VA_ARGS__)
71
- #define strncasecmp_P(...) ::strncasecmp(__VA_ARGS__)
72
- #define strncat_P(...) ::strncat(__VA_ARGS__)
73
- #define strncpy_P(...) ::strncpy(__VA_ARGS__)
74
- #define strpbrk_P(...) ::strpbrk(__VA_ARGS__)
75
- #define strrchr_P(...) ::strrchr(__VA_ARGS__)
76
- #define strsep_P(...) ::strsep(__VA_ARGS__)
77
- #define strspn_P(...) ::strspn(__VA_ARGS__)
78
- #define strstr_P(...) ::strstr(__VA_ARGS__)
79
- #define strtok_P(...) ::strtok(__VA_ARGS__)
80
- #define strtok_P(...) ::strtok(__VA_ARGS__)
81
- #define strlen_P(...) ::strlen(__VA_ARGS__)
82
- #define strnlen_P(...) ::strnlen(__VA_ARGS__)
83
- #define memcpy_P(...) ::memcpy(__VA_ARGS__)
84
- #define strcpy_P(...) ::strcpy(__VA_ARGS__)
85
- #define strncpy_P(...) ::strncpy(__VA_ARGS__)
86
- #define strcat_P(...) ::strcat(__VA_ARGS__)
87
- #define strlcat_P(...) ::strlcat(__VA_ARGS__)
88
- #define strncat_P(...) ::strncat(__VA_ARGS__)
89
- #define strcmp_P(...) ::strcmp(__VA_ARGS__)
90
- #define strncmp_P(...) ::strncmp(__VA_ARGS__)
91
- #define strcasecmp_P(...) ::strcasecmp(__VA_ARGS__)
92
- #define strncasecmp_P(...) ::strncasecmp(__VA_ARGS__)
93
- #define strstr_P(...) ::strstr(__VA_ARGS__)
94
- #define strlcpy_P(...) ::strlcpy(__VA_ARGS__)
95
- #define memcmp_P(...) ::memcmp(__VA_ARGS__)
60
+ inline const void * memchr_P(const void *s, int val, size_t len) { return memchr(s, val, len); }
61
+ inline int memcmp_P(const void *s1, const void *s2, size_t len) { return memcmp(s1, s2, len); }
62
+ inline void *memcpy_P(void *dest, const void *src, size_t n) { return memcpy(dest, src, n); }
63
+ inline char *strcat_P(char *dest, const char *src) { return strcat(dest, src); }
64
+ inline const char *strchr_P(const char *s, int val) { return strchr(s, val); }
65
+ inline int strcmp_P(const char *s1, const char *s2) { return strcmp(s1, s2); }
66
+ inline char *strcpy_P(char *dest, const char *src) { return strcpy(dest, src); }
67
+ inline size_t strcspn_P(const char *s, const char *reject) { return strcspn(s, reject); }
68
+ // strlcat and strlcpy are AVR-specific and not entirely trivial to reimplement using strncat it seems
69
+ //inline size_t strlcat_P(char *dst, const char *src, size_t siz) { return strlcat(dst, src, siz); }
70
+ //inline size_t strlcpy_P(char *dst, const char *src, size_t siz) { return strlcpy(dst, src, siz); }
71
+ //inline size_t strlcat_PF(char *dst, uint_farptr_t src, size_t n) { return strlcat(dst, (const char*)src, n); }
72
+ //inline size_t strlcpy_PF(char *dst, uint_farptr_t src, size_t siz) { return strlcpy(dst, (const char*)src, siz); }
73
+ inline int strncmp_P(const char *s1, const char *s2, size_t n) { return strncmp(s1, s2, n); }
74
+ inline char *strncat_P(char *dest, const char *src, size_t len) { return strncat(dest, src, len); }
75
+ inline char *strncpy_P(char *dest, const char *src, size_t n) { return strncpy(dest, src, n); }
76
+ inline char *strpbrk_P(const char *s, const char *accept) { return (char*)strpbrk(s, accept); }
77
+ inline const char *strrchr_P(const char *s, int val) { return strrchr(s, val); }
78
+ inline size_t strspn_P(const char *s, const char *accept) { return strspn(s, accept); }
79
+ inline char *strstr_P(const char *s1, const char *s2) { return (char*)strstr(s1, s2); }
80
+ inline char *strtok_P(char *s, const char * delim) { return strtok(s, delim); }
81
+ inline size_t strlen_PF(uint_farptr_t s) { return strlen((char*)s); }
82
+ inline void *memcpy_PF(void *dest, uint_farptr_t src, size_t n) { return memcpy(dest, (const char*)src, n); }
83
+ inline char *strcpy_PF(char *dst, uint_farptr_t src) { return strcpy(dst, (const char*)src); }
84
+ inline char *strncpy_PF(char *dst, uint_farptr_t src, size_t n) { return strncpy(dst, (const char*)src, n); }
85
+ inline char *strcat_PF(char *dst, uint_farptr_t src) { return strcat(dst, (const char*)src); }
86
+ inline char *strncat_PF(char *dst, uint_farptr_t src, size_t n) { return strncat(dst, (const char*)src, n); }
87
+ inline int strcmp_PF(const char *s1, uint_farptr_t s2) { return strcmp(s1, (const char*)s2); }
88
+ inline int strncmp_PF(const char *s1, uint_farptr_t s2, size_t n) { return strncmp(s1, (const char*)s2, n); }
89
+ inline char *strstr_PF(const char *s1, uint_farptr_t s2) { return (char*)strstr(s1, (const char*)s2); }
90
+ inline int memcmp_PF(const void *s1, uint_farptr_t s2, size_t len) { return memcmp(s1, (const char*)s2, len); }
91
+ inline size_t strlen_P(const char *src) { return strlen(src); }
92
+
93
+ // TODO: These functions cannot be found on the CYGWIN test build for
94
+ // some reason, so disable them for now. Most of these are less common
95
+ // and/or GNU-specific addons anyway
96
+ //inline void *memccpy_P(void *dest, const void *src, int val, size_t len) { return memccpy(dest, src, val, len); }
97
+ //inline void *memmem_P(const void *s1, size_t len1, const void *s2, size_t len2) { return memmem(s1, len1, s2, len2); }
98
+ //inline const void *memrchr_P(const void *src, int val, size_t len) { return memrchr(src, val, len); }
99
+ //inline const char *strchrnul_P(const char *s, int c) { return strchrnul(s, c); }
100
+ //inline int strcasecmp_P(const char *s1, const char *s2) { return strcasecmp(s1, s2); }
101
+ //inline char *strcasestr_P(const char *s1, const char *s2) { return (char*)strcasestr(s1, s2); }
102
+ //inline int strncasecmp_P(const char *s1, const char *s2, size_t n) { return strncasecmp(s1, s2, n); }
103
+ //inline char *strsep_P(char **sp, const char *delim) { return strsep(sp, delim); }
104
+ //inline char *strtok_r_P(char *string, const char *delim, char **last) { return strtok_r(string, delim, last); }
105
+ //inline int strcasecmp_PF(const char *s1, uint_farptr_t s2) { return strcasecmp(s1, (const char*)s2); }
106
+ //inline int strncasecmp_PF(const char *s1, uint_farptr_t s2, size_t n) { return strncasecmp(s1, (const char*)s2, n); }
107
+ //inline size_t strnlen_P(uint_farptr_t s, size_t len) { return strnlen((char*)s, len); }
108
+
109
+ // These are normally defined by stdio.h on AVR, but we cannot override that
110
+ // include file (at least not without no longer being able to include the
111
+ // original as well), so just define these here. It seems likely that any
112
+ // sketch that uses these progmem-stdio functions will also include pgmspace.h
113
+ inline int vfprintf_P(FILE *stream, const char *__fmt, va_list __ap) { return vfprintf(stream, __fmt, __ap); }
114
+ inline int printf_P(const char *__fmt, ...) { va_list args; va_start(args, __fmt); return vprintf(__fmt, args); va_end(args); }
115
+ inline int sprintf_P(char *s, const char *__fmt, ...) { va_list args; va_start(args, __fmt); return sprintf(s, __fmt, args); va_end(args); }
116
+ inline int snprintf_P(char *s, size_t __n, const char *__fmt, ...) { va_list args; va_start(args, __fmt); return vsnprintf(s, __n, __fmt, args); va_end(args); }
117
+ inline int vsprintf_P(char *s, const char *__fmt, va_list ap) { return vsprintf(s, __fmt, ap); }
118
+ inline int vsnprintf_P(char *s, size_t __n, const char *__fmt, va_list ap) { return vsnprintf(s, __n, __fmt, ap); }
119
+ inline int fprintf_P(FILE *stream, const char *__fmt, ...) { va_list args; va_start(args, __fmt); return vfprintf(stream, __fmt, args); va_end(args); }
120
+ inline int fputs_P(const char *str, FILE *__stream) { return fputs(str, __stream); }
121
+ inline int puts_P(const char *str) { return puts(str); }
122
+ inline int vfscanf_P(FILE *stream, const char *__fmt, va_list __ap) { return vfscanf(stream, __fmt, __ap); }
123
+ inline int fscanf_P(FILE *stream, const char *__fmt, ...) { va_list args; va_start(args, __fmt); return vfscanf(stream, __fmt, args); va_end(args); }
124
+ inline int scanf_P(const char *__fmt, ...) { va_list args; va_start(args, __fmt); return vscanf(__fmt, args); va_end(args); }
125
+ inline int sscanf_P(const char *buf, const char *__fmt, ...) { va_list args; va_start(args, __fmt); return vsscanf(buf, __fmt, args); va_end(args); }
@@ -69,6 +69,23 @@ class Test
69
69
  }
70
70
  }
71
71
 
72
+ // non-comparative assert
73
+ void onAssert(
74
+ const char* file,
75
+ int line,
76
+ const char* description,
77
+ bool pass
78
+ ) {
79
+ cerr << " " << (pass ? "" : "not ") << "ok " << ++mAssertCounter << " - " << description << endl;
80
+ if (!pass) {
81
+ cerr << " ---" << endl;
82
+ cerr << " at:" << endl;
83
+ cerr << " file: " << file << endl;
84
+ cerr << " line: " << line << endl;
85
+ cerr << " ..." << endl;
86
+ }
87
+ }
88
+
72
89
  template <typename A, typename B> void onAssert(
73
90
  const char* file,
74
91
  int line,
@@ -194,6 +211,21 @@ class Test
194
211
  excise();
195
212
  }
196
213
 
214
+ bool assertion(
215
+ const char *file,
216
+ int line,
217
+ const char *description,
218
+ bool ok)
219
+ {
220
+ if (mReporter) {
221
+ mReporter->onAssert(file, line, description, ok);
222
+ }
223
+
224
+ if (!ok)
225
+ fail();
226
+ return ok;
227
+ }
228
+
197
229
  template <typename A, typename B>
198
230
  bool assertion(
199
231
  const char *file,
@@ -6,9 +6,19 @@
6
6
 
7
7
  #include "Compare.h"
8
8
 
9
- #define testBehaviorOp(die, desc, rel1, arg1, op, op_name, rel2, arg2) \
9
+ #define arduinoCITestBehaviorExp(die, desc, pass) \
10
+ do \
11
+ { \
12
+ if (!assertion(__FILE__, __LINE__, \
13
+ desc, pass)) \
14
+ { \
15
+ if (die) return; \
16
+ } \
17
+ } while (0)
18
+
19
+ #define arduinoCITestBehaviorOp(die, desc, rel1, arg1, op, op_name, rel2, arg2) \
10
20
  do \
11
- { \
21
+ { \
12
22
  if (!assertion<typeof(arg1), typeof(arg2)>(__FILE__, __LINE__, \
13
23
  desc, \
14
24
  rel1, #arg1, (arg1), \
@@ -22,34 +32,52 @@
22
32
 
23
33
 
24
34
  // helper define for the operators below
25
- #define assertOp(desc, rel1, arg1, op, op_name, rel2, arg2) \
26
- testBehaviorOp(false, desc, rel1, arg1, op, op_name, rel2, arg2)
35
+ #define arduinoCIAssertOp(desc, rel1, arg1, op, op_name, rel2, arg2) \
36
+ arduinoCITestBehaviorOp(false, "assert" desc, rel1, arg1, op, op_name, rel2, arg2)
27
37
 
28
- #define assureOp(desc, rel1, arg1, op, op_name, rel2, arg2) \
29
- testBehaviorOp(true, desc, rel1, arg1, op, op_name, rel2, arg2)
38
+ #define arduinoCIAssureOp(desc, rel1, arg1, op, op_name, rel2, arg2) \
39
+ arduinoCITestBehaviorOp(true, "assure" desc, rel1, arg1, op, op_name, rel2, arg2)
30
40
 
31
41
 
32
42
  /** macro generates optional output and calls fail() but does not return if false. */
33
- #define assertEqual(arg1,arg2) assertOp("assertEqual","expected",arg1,compareEqual,"==","actual",arg2)
34
- #define assertNotEqual(arg1,arg2) assertOp("assertNotEqual","unwanted",arg1,compareNotEqual,"!=","actual",arg2)
35
- #define assertLess(arg1,arg2) assertOp("assertLess","lowerBound",arg1,compareLess,"<","upperBound",arg2)
36
- #define assertMore(arg1,arg2) assertOp("assertMore","upperBound",arg1,compareMore,">","lowerBound",arg2)
37
- #define assertLessOrEqual(arg1,arg2) assertOp("assertLessOrEqual","lowerBound",arg1,compareLessOrEqual,"<=","upperBound",arg2)
38
- #define assertMoreOrEqual(arg1,arg2) assertOp("assertMoreOrEqual","upperBound",arg1,compareMoreOrEqual,">=","lowerBound",arg2)
39
- #define assertTrue(arg) assertEqual(true, arg)
40
- #define assertFalse(arg) assertEqual(false, arg)
41
- #define assertNull(arg) assertEqual((void*)NULL, (void*)arg)
42
- #define assertNotNull(arg) assertNotEqual((void*)NULL, (void*)arg)
43
+ #define assertTrue(arg) arduinoCITestBehaviorExp(false, "True " #arg, (arg))
44
+ #define assertFalse(arg) arduinoCITestBehaviorExp(false, "False " #arg, !(arg))
45
+ #define assertNull(arg) arduinoCITestBehaviorExp(false, "Null " #arg, ((void*)NULL == (void*)(arg)))
46
+ #define assertNotNull(arg) arduinoCITestBehaviorExp(false, "NotNull " #arg, ((void*)NULL != (void*)(arg)))
47
+ #define assertEqual(arg1,arg2) arduinoCIAssertOp("Equal","expected",arg1,compareEqual,"==","actual",arg2)
48
+ #define assertNotEqual(arg1,arg2) arduinoCIAssertOp("NotEqual","unwanted",arg1,compareNotEqual,"!=","actual",arg2)
49
+ #define assertComparativeEquivalent(arg1,arg2) arduinoCIAssertOp("ComparativeEquivalent","expected",arg1,compareEquivalent,"!<>","actual",arg2)
50
+ #define assertComparativeNotEquivalent(arg1,arg2) arduinoCIAssertOp("ComparativeNotEquivalent","unwanted",arg1,compareNotEquivalent,"<>","actual",arg2)
51
+ #define assertLess(arg1,arg2) arduinoCIAssertOp("Less","lowerBound",arg1,compareLess,"<","actual",arg2)
52
+ #define assertMore(arg1,arg2) arduinoCIAssertOp("More","upperBound",arg1,compareMore,">","actual",arg2)
53
+ #define assertLessOrEqual(arg1,arg2) arduinoCIAssertOp("LessOrEqual","lowerBound",arg1,compareLessOrEqual,"<=","actual",arg2)
54
+ #define assertMoreOrEqual(arg1,arg2) arduinoCIAssertOp("MoreOrEqual","upperBound",arg1,compareMoreOrEqual,">=","actual",arg2)
55
+
56
+ #define assertEqualFloat(arg1, arg2, arg3) arduinoCIAssertOp("EqualFloat", "epsilon", arg3, compareMoreOrEqual, ">=", "actualDifference", fabs(arg1 - arg2))
57
+ #define assertNotEqualFloat(arg1, arg2, arg3) arduinoCIAssertOp("NotEqualFloat", "epsilon", arg3, compareLessOrEqual, "<=", "insufficientDifference", fabs(arg1 - arg2))
58
+ #define assertInfinity(arg) arduinoCITestBehaviorExp(false, "Infinity " #arg, isinf(arg))
59
+ #define assertNotInfinity(arg) arduinoCITestBehaviorExp(false, "NotInfinity " #arg, !isinf(arg))
60
+ #define assertNAN(arg) arduinoCITestBehaviorExp(false, "NAN " #arg, isnan(arg))
61
+ #define assertNotNAN(arg) arduinoCITestBehaviorExp(false, "NotNAN " #arg, !isnan(arg))
62
+
43
63
 
44
64
  /** macro generates optional output and calls fail() followed by a return if false. */
45
- #define assureEqual(arg1,arg2) assureOp("assureEqual","expected",arg1,compareEqual,"==","actual",arg2)
46
- #define assureNotEqual(arg1,arg2) assureOp("assureNotEqual","unwanted",arg1,compareNotEqual,"!=","actual",arg2)
47
- #define assureLess(arg1,arg2) assureOp("assureLess","lowerBound",arg1,compareLess,"<","upperBound",arg2)
48
- #define assureMore(arg1,arg2) assureOp("assureMore","upperBound",arg1,compareMore,">","lowerBound",arg2)
49
- #define assureLessOrEqual(arg1,arg2) assureOp("assureLessOrEqual","lowerBound",arg1,compareLessOrEqual,"<=","upperBound",arg2)
50
- #define assureMoreOrEqual(arg1,arg2) assureOp("assureMoreOrEqual","upperBound",arg1,compareMoreOrEqual,">=","lowerBound",arg2)
51
- #define assureTrue(arg) assureEqual(true, arg)
52
- #define assureFalse(arg) assureEqual(false, arg)
53
- #define assureNull(arg) assureEqual((void*)NULL, (void*)arg)
54
- #define assureNotNull(arg) assureNotEqual((void*)NULL, (void*)arg)
65
+ #define assureTrue(arg) arduinoCITestBehaviorExp(true, "True " #arg, (arg))
66
+ #define assureFalse(arg) arduinoCITestBehaviorExp(true, "False " #arg, !(arg))
67
+ #define assureNull(arg) arduinoCITestBehaviorExp(true, "Null " #arg, ((void*)NULL == (void*)(arg)))
68
+ #define assureNotNull(arg) arduinoCITestBehaviorExp(true, "NotNull " #arg, ((void*)NULL != (void*)(arg)))
69
+ #define assureEqual(arg1,arg2) arduinoCIAssureOp("Equal","expected",arg1,compareEqual,"==","actual",arg2)
70
+ #define assureNotEqual(arg1,arg2) arduinoCIAssureOp("NotEqual","unwanted",arg1,compareNotEqual,"!=","actual",arg2)
71
+ #define assureComparativeEquivalent(arg1,arg2) arduinoCIAssureOp("ComparativeEquivalent","expected",arg1,compareEquivalent,"!<>","actual",arg2)
72
+ #define assureComparativeNotEquivalent(arg1,arg2) arduinoCIAssureOp("ComparativeNotEquivalent","unwanted",arg1,compareNotEquivalent,"<>","actual",arg2)
73
+ #define assureLess(arg1,arg2) arduinoCIAssureOp("Less","lowerBound",arg1,compareLess,"<","actual",arg2)
74
+ #define assureMore(arg1,arg2) arduinoCIAssureOp("More","upperBound",arg1,compareMore,">","actual",arg2)
75
+ #define assureLessOrEqual(arg1,arg2) arduinoCIAssureOp("LessOrEqual","lowerBound",arg1,compareLessOrEqual,"<=","actual",arg2)
76
+ #define assureMoreOrEqual(arg1,arg2) arduinoCIAssureOp("MoreOrEqual","upperBound",arg1,compareMoreOrEqual,">=","actual",arg2)
55
77
 
78
+ #define assureEqualFloat(arg1, arg2, arg3) arduinoCIAssureOp("EqualFloat", "epsilon", arg3, compareMoreOrEqual, ">=", "actualDifference", fabs(arg1 - arg2))
79
+ #define assureNotEqualFloat(arg1, arg2, arg3) arduinoCIAssureOp("NotEqualFloat", "epsilon", arg3, compareLessOrEqual, "<=", "insufficientDifference", fabs(arg1 - arg2))
80
+ #define assureInfinity(arg) arduinoCITestBehaviorExp(true, "Infinity " #arg, isinf(arg))
81
+ #define assureNotInfinity(arg) arduinoCITestBehaviorExp(true, "NotInfinity " #arg, !isinf(arg))
82
+ #define assureNAN(arg) arduinoCITestBehaviorExp(true, "NAN " #arg, isnan(arg))
83
+ #define assureNotNAN(arg) arduinoCITestBehaviorExp(true, "NotNAN " #arg, !isnan(arg))
@@ -10,12 +10,14 @@ template < typename A, typename B > struct Compare
10
10
  if (b<a) return 1;
11
11
  return 0;
12
12
  }
13
- inline static bool equal(const A &a,const B &b) { return (!(a < b)) && (!(b < a)); }
14
- inline static bool notEqual(const A &a,const B &b) { return (a<b) || (b<a); }
15
- inline static bool less(const A &a,const B &b) { return a<b; }
16
- inline static bool more(const A &a,const B &b) { return b<a; }
17
- inline static bool lessOrEqual(const A &a,const B &b) { return !(b<a); }
18
- inline static bool moreOrEqual(const A &a,const B &b) { return !(a<b); }
13
+ inline static bool equal(const A &a,const B &b) { return a==b; }
14
+ inline static bool notEqual(const A &a,const B &b) { return a!=b; }
15
+ inline static bool equivalent(const A &a,const B &b) { return (!(a < b)) && (!(b < a)); }
16
+ inline static bool notEquivalent(const A &a,const B &b) { return (a<b) || (b<a); }
17
+ inline static bool less(const A &a,const B &b) { return a<b; }
18
+ inline static bool more(const A &a,const B &b) { return b<a; }
19
+ inline static bool lessOrEqual(const A &a,const B &b) { return !(b<a); }
20
+ inline static bool moreOrEqual(const A &a,const B &b) { return !(a<b); }
19
21
  };
20
22
 
21
23
  // helpers for macros
@@ -57,56 +59,61 @@ inline static int arduinoCICompareBetween(const __FlashStringHelper * const &a,c
57
59
 
58
60
 
59
61
  // this macro works for all the string-based comparisons
62
+ // note that it substitutes equivalence for equality
60
63
  // but just in case, https://stackoverflow.com/a/13842784/2063546
61
- #define comparisonTemplateMacro(T1, T1m, T2, T2m, betweenImpl, ...) \
62
- template < __VA_ARGS__ > struct Compare<T1 T1m, T2 T2m>; \
63
- template < __VA_ARGS__ > struct Compare<T1 T1m, T2 T2m> \
64
- { \
65
- inline static int between( T1 const (&a)T1m, T2 const (&b)T2m) { return betweenImpl; } \
66
- inline static bool equal( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) == 0; } \
67
- inline static bool notEqual( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) != 0; } \
68
- inline static bool less( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) < 0; } \
69
- inline static bool more( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) > 0; } \
70
- inline static bool lessOrEqual(T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) <= 0; } \
71
- inline static bool moreOrEqual(T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) >= 0; } \
64
+ #define eqComparisonTemplateMacro(T1, T1m, T2, T2m, betweenImpl, ...) \
65
+ template < __VA_ARGS__ > struct Compare<T1 T1m, T2 T2m>; \
66
+ template < __VA_ARGS__ > struct Compare<T1 T1m, T2 T2m> \
67
+ { \
68
+ inline static int between( T1 const (&a)T1m, T2 const (&b)T2m) { return betweenImpl; } \
69
+ inline static bool equal( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) == 0; } \
70
+ inline static bool notEqual( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) != 0; } \
71
+ inline static bool equivalent( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) == 0; } \
72
+ inline static bool notEquivalent(T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) != 0; } \
73
+ inline static bool less( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) < 0; } \
74
+ inline static bool more( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) > 0; } \
75
+ inline static bool lessOrEqual( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) <= 0; } \
76
+ inline static bool moreOrEqual( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) >= 0; } \
72
77
  };
73
78
 
74
- comparisonTemplateMacro(String, , String, , a.compareTo(b))
75
- comparisonTemplateMacro(String, , const char *, , a.compareTo(b))
79
+ eqComparisonTemplateMacro(String, , String, , a.compareTo(b))
80
+ eqComparisonTemplateMacro(String, , const char *, , a.compareTo(b))
76
81
  #if defined(F)
77
- comparisonTemplateMacro(String, , const __FlashStringHelper *, , arduinoCICompareBetween(a, b))
78
- comparisonTemplateMacro(const char *,, const __FlashStringHelper *, , strcmp_P(a,(const char *)b))
79
- comparisonTemplateMacro(const __FlashStringHelper *, , String, , -arduinoCICompareBetween(b, a))
80
- comparisonTemplateMacro(const __FlashStringHelper *, , const char *, , -strcmp_P(b,(const char *)a))
81
- comparisonTemplateMacro(const __FlashStringHelper *, , const __FlashStringHelper *, , arduinoCICompareBetween(a, b))
82
- comparisonTemplateMacro(const __FlashStringHelper *, , char *, , -strcmp_P(b,(const char *)a))
83
- comparisonTemplateMacro(char *, , const __FlashStringHelper *, , strcmp_P(a,(const char *)b))
84
- comparisonTemplateMacro(const __FlashStringHelper *, , char, [M], -strcmp_P(b,(const char *)a), size_t M)
85
- comparisonTemplateMacro(char, [N], const __FlashStringHelper *, , strcmp_P(a,(const char *)b), size_t N)
82
+ eqComparisonTemplateMacro(String, , const __FlashStringHelper *, , arduinoCICompareBetween(a, b))
83
+ eqComparisonTemplateMacro(const char *,, const __FlashStringHelper *, , strcmp_P(a,(const char *)b))
84
+ eqComparisonTemplateMacro(const __FlashStringHelper *, , String, , -arduinoCICompareBetween(b, a))
85
+ eqComparisonTemplateMacro(const __FlashStringHelper *, , const char *, , -strcmp_P(b,(const char *)a))
86
+ eqComparisonTemplateMacro(const __FlashStringHelper *, , const __FlashStringHelper *, , arduinoCICompareBetween(a, b))
87
+ eqComparisonTemplateMacro(const __FlashStringHelper *, , char *, , -strcmp_P(b,(const char *)a))
88
+ eqComparisonTemplateMacro(char *, , const __FlashStringHelper *, , strcmp_P(a,(const char *)b))
89
+ eqComparisonTemplateMacro(const __FlashStringHelper *, , char, [M], -strcmp_P(b,(const char *)a), size_t M)
90
+ eqComparisonTemplateMacro(char, [N], const __FlashStringHelper *, , strcmp_P(a,(const char *)b), size_t N)
86
91
  #endif
87
- comparisonTemplateMacro(String, , char *, , a.compareTo(b))
88
- comparisonTemplateMacro(const char *, , String, , -b.compareTo(a))
89
- comparisonTemplateMacro(const char *, , const char *, , strcmp(a,b))
90
- comparisonTemplateMacro(const char *, , char *, , strcmp(a,b))
91
- comparisonTemplateMacro(char *, , String, , -b.compareTo(a))
92
- comparisonTemplateMacro(char *, , const char *, , strcmp(a,b))
93
- comparisonTemplateMacro(char *, , char *, , strcmp(a,b))
94
- comparisonTemplateMacro(String, , char, [M], a.compareTo(b), size_t M)
95
- comparisonTemplateMacro(const char *, , char, [M], strcmp(a,b), size_t M)
96
- comparisonTemplateMacro(char *, , char, [M], strcmp(a,b), size_t M)
97
- comparisonTemplateMacro(char, [N], String, , -b.compareTo(a), size_t N)
98
- comparisonTemplateMacro(char, [N], const char *, , strcmp(a,b), size_t N)
99
- comparisonTemplateMacro(char, [N], char *, , strcmp(a,b), size_t N)
100
- comparisonTemplateMacro(char, [N], char, [M], strcmp(a,b), size_t N, size_t M)
92
+ eqComparisonTemplateMacro(String, , char *, , a.compareTo(b))
93
+ eqComparisonTemplateMacro(const char *, , String, , -b.compareTo(a))
94
+ eqComparisonTemplateMacro(const char *, , const char *, , strcmp(a,b))
95
+ eqComparisonTemplateMacro(const char *, , char *, , strcmp(a,b))
96
+ eqComparisonTemplateMacro(char *, , String, , -b.compareTo(a))
97
+ eqComparisonTemplateMacro(char *, , const char *, , strcmp(a,b))
98
+ eqComparisonTemplateMacro(char *, , char *, , strcmp(a,b))
99
+ eqComparisonTemplateMacro(String, , char, [M], a.compareTo(b), size_t M)
100
+ eqComparisonTemplateMacro(const char *, , char, [M], strcmp(a,b), size_t M)
101
+ eqComparisonTemplateMacro(char *, , char, [M], strcmp(a,b), size_t M)
102
+ eqComparisonTemplateMacro(char, [N], String, , -b.compareTo(a), size_t N)
103
+ eqComparisonTemplateMacro(char, [N], const char *, , strcmp(a,b), size_t N)
104
+ eqComparisonTemplateMacro(char, [N], char *, , strcmp(a,b), size_t N)
105
+ eqComparisonTemplateMacro(char, [N], char, [M], strcmp(a,b), size_t N, size_t M)
101
106
 
102
- comparisonTemplateMacro(A, , std::nullptr_t, , a ? 1 : 0, typename A)
103
- comparisonTemplateMacro(std::nullptr_t, , B, , b ? -1 : 0, typename B)
107
+ eqComparisonTemplateMacro(A, , std::nullptr_t, , a ? 1 : 0, typename A)
108
+ eqComparisonTemplateMacro(std::nullptr_t, , B, , b ? -1 : 0, typename B)
104
109
 
105
110
  // super general comparisons
106
- template <typename A, typename B> int compareBetween( const A &a, const B &b) { return Compare<A, B>::between( a, b); }
107
- template <typename A, typename B> bool compareEqual( const A &a, const B &b) { return Compare<A, B>::equal( a, b); }
108
- template <typename A, typename B> bool compareNotEqual( const A &a, const B &b) { return Compare<A, B>::notEqual( a, b); }
109
- template <typename A, typename B> bool compareLess( const A &a, const B &b) { return Compare<A, B>::less( a, b); }
110
- template <typename A, typename B> bool compareMore( const A &a, const B &b) { return Compare<A, B>::more( a, b); }
111
- template <typename A, typename B> bool compareLessOrEqual(const A &a, const B &b) { return Compare<A, B>::lessOrEqual(a, b); }
112
- template <typename A, typename B> bool compareMoreOrEqual(const A &a, const B &b) { return Compare<A, B>::moreOrEqual(a, b); }
111
+ template <typename A, typename B> int compareBetween( const A &a, const B &b) { return Compare<A, B>::between( a, b); }
112
+ template <typename A, typename B> bool compareEqual( const A &a, const B &b) { return Compare<A, B>::equal( a, b); }
113
+ template <typename A, typename B> bool compareNotEqual( const A &a, const B &b) { return Compare<A, B>::notEqual( a, b); }
114
+ template <typename A, typename B> bool compareEquivalent( const A &a, const B &b) { return Compare<A, B>::equivalent( a, b); }
115
+ template <typename A, typename B> bool compareNotEquivalent(const A &a, const B &b) { return Compare<A, B>::notEquivalent(a, b); }
116
+ template <typename A, typename B> bool compareLess( const A &a, const B &b) { return Compare<A, B>::less( a, b); }
117
+ template <typename A, typename B> bool compareMore( const A &a, const B &b) { return Compare<A, B>::more( a, b); }
118
+ template <typename A, typename B> bool compareLessOrEqual( const A &a, const B &b) { return Compare<A, B>::lessOrEqual( a, b); }
119
+ template <typename A, typename B> bool compareMoreOrEqual( const A &a, const B &b) { return Compare<A, B>::moreOrEqual( a, b); }
@@ -2,4 +2,8 @@
2
2
 
3
3
  #include <ostream>
4
4
 
5
+ #if (defined __apple_build_version__) && (__apple_build_version__ >= 12000000)
6
+ // defined in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ostream:223:20
7
+ #else
5
8
  inline std::ostream& operator << (std::ostream& out, const std::nullptr_t &np) { return out << "nullptr"; }
9
+ #endif