AUnit  1.7.1
Unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test.
Compare.cpp
1 /*
2 MIT License
3 
4 Copyright (c) 2018 Brian T. Park
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 
25 /*
26 Design Notes:
27 ============
28 
29 Template Specialization:
30 -----------------------
31 One way to implement the compareEqual() for these types is to use template
32 specialization. The problem with Template specialization is that templates
33 use strict type matching, and does not perform the normal implicit type
34 conversion, including const-casting. Therefore, all of the various c-style
35 string types, for example:
36 
37  - char*
38  - const char*
39  - char[1]
40  - char[N]
41  - const char[1]
42  - const char[N]
43 
44 are considered to be different types under the C++ templating system. This
45 causes a combinatorial explosion of template specialization which produces
46 code that is difficult to understand, test and maintain.
47 An example can be seen in the Compare.h file of the ArduinoUnit project:
48 https://github.com/mmurdoch/arduinounit/blob/master/src/ArduinoUnitUtility/Compare.h
49 
50 Function Overloading:
51 ---------------------
52 In this project, I used function overloading instead of template
53 specialization. Function overloading handles c-style strings (i.e. character
54 arrays) naturally, in the way most users expect. For example, (char*) is
55 automarically cast to (const char*), and (char[N]) is autonmatically
56 cast to (const char*).
57 
58 For the primitive value types (e.g. (char), (int), (unsigned char), etc.) I
59 attempted to use a generic templatized version, using sonmething like:
60 
61  template<typename T>
62  compareEqual(const T& a, const T& b) { ... }
63 
64 However, this template introduced this method:
65 
66  compareEqual(char* const& a, char* const& b);
67 
68 that seemed to take precedence over the explicitly defined overload:
69 
70  compareEqual(const char* a, const char*b);
71 
72 When the compareEqual() method is called with a (char*) or a (char[N]),
73 like this:
74 
75  char a[3] = {...};
76  char b[4] = {...};
77  compareEqual(a, b);
78 
79 this calls compareEqual(char* const&, const* const&), which is the wrong
80 version for a c-style string. The only way I could get this to work was to
81 avoid templates completely and manually define all the function overloads
82 even for primitive integer types.
83 
84 Implicit Conversions:
85 ---------------------
86 For basic primitive types, I depend on some casts to avoid having to define
87 some functions. I assume that signed and unsigned integers smaller or equal
88 to (int) will be converted to an (int) to match compareEqual(int, int).
89 
90 I provided an explicit compareEqual(char, char) overload because in C++, a
91 (char) type is distinct from (signed char) and (unsigned char).
92 
93 Technically, there should be a (long long) version and an (unsigned long
94 long) version of compareEqual(). However, it turns out that the Arduino
95 Print::print() method does not have an overload for these types, so it would
96 not do us much good to provide an assertEqual() or compareEqual() for the
97 (long long) and (unsigned long long) types.
98 
99 Custom Assert and Compare Functions:
100 ------------------------------------
101 Another advantage of using function overloading instead of template
102 specialization is that the user is able to add additional function overloads
103 into the 'aunit' namespace. This should allow the user to define the various
104 comporeXxx() and assertXxx() functions for a custom class. I have not
105 tested this though.
106 
107 Comparing Flash Strings:
108 ------------------------
109 Flash memory must be read using 4-byte alignment on the ESP8266. AVR doesn't
110 care. Teensy-ARM fakes the flash memory API but really just uses the normal
111 static RAM. The following code for comparing two (__FlashStringHelper*)
112 against each other will work for all 3 environments.
113 
114 Inlining:
115 --------
116 Even though most of these functions are one-liners, there is no advantage to
117 inlining them because they are almost always used through a function pointer.
118 */
119 
120 #include <stdint.h>
121 #include <string.h>
122 #include <math.h> // fabs()
123 #include <WString.h>
124 #include "Flash.h"
125 #include "Compare.h"
126 
127 namespace aunit {
128 namespace internal {
129 
130 //---------------------------------------------------------------------------
131 // compareString()
132 //---------------------------------------------------------------------------
133 
134 int compareString(const char* a, const char* b) {
135  if (a == b) { return 0; }
136  if (a == nullptr) { return -1; }
137  if (b == nullptr) { return 1; }
138  return strcmp(a, b);
139 }
140 
141 int compareString(const char* a, const String& b) {
142  if (a == nullptr) { return -1; }
143  return strcmp(a, b.c_str());
144 }
145 
146 int compareString(const char* a, const __FlashStringHelper* b) {
147  if (a == (const char*) b) { return 0; }
148  if (a == nullptr) { return -1; }
149  if (b == nullptr) { return 1; }
150  return strcmp_P(a, (const char*) b);
151 }
152 
153 int compareString(const String& a, const char* b) {
154  return -compareString(b, a);
155 }
156 
157 int compareString(const String& a, const String& b) {
158  return strcmp(a.c_str(), b.c_str());
159 }
160 
161 int compareString(const String& a, const __FlashStringHelper* b) {
162  if (b == nullptr) { return 1; }
163  return strcmp_P(a.c_str(), (const char*) b);
164 }
165 
166 int compareString(const __FlashStringHelper* a, const char* b) {
167  return -compareString(b, a);
168 }
169 
170 int compareString(const __FlashStringHelper* a, const String& b) {
171  return -compareString(b, a);
172 }
173 
174 // On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
175 // memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
176 // optimizing for 4-byte alignment here.
177 int compareString(const __FlashStringHelper* a, const __FlashStringHelper* b) {
178  if (a == b) { return 0; }
179  if (a == nullptr) { return -1; }
180  if (b == nullptr) { return 1; }
181  const char* aa = reinterpret_cast<const char*>(a);
182  const char* bb = reinterpret_cast<const char*>(b);
183 
184  while (true) {
185  uint8_t ca = pgm_read_byte(aa);
186  uint8_t cb = pgm_read_byte(bb);
187  if (ca != cb) return (int) ca - (int) cb;
188  if (ca == '\0') return 0;
189  aa++;
190  bb++;
191  }
192 }
193 
194 //---------------------------------------------------------------------------
195 // compareStringCase()
196 //---------------------------------------------------------------------------
197 
198 int compareStringCase(const char* a, const char* b) {
199  if (a == b) { return 0; }
200  if (a == nullptr) { return -1; }
201  if (b == nullptr) { return 1; }
202  return strcasecmp(a, b);
203 }
204 
205 int compareStringCase(const char* a, const String& b) {
206  if (a == nullptr) { return -1; }
207  return strcasecmp(a, b.c_str());
208 }
209 
210 int compareStringCase(const char* a, const __FlashStringHelper* b) {
211  if (a == (const char*) b) { return 0; }
212  if (a == nullptr) { return -1; }
213  if (b == nullptr) { return 1; }
214  return strcasecmp_P(a, (const char*) b);
215 }
216 
217 int compareStringCase(const String& a, const char* b) {
218  return -compareStringCase(b, a);
219 }
220 
221 int compareStringCase(const String& a, const String& b) {
222  return strcasecmp(a.c_str(), b.c_str());
223 }
224 
225 int compareStringCase(const String& a, const __FlashStringHelper* b) {
226  if (b == nullptr) { return 1; }
227  return strcasecmp_P(a.c_str(), (const char*) b);
228 }
229 
230 int compareStringCase(const __FlashStringHelper* a, const char* b) {
231  return -compareStringCase(b, a);
232 }
233 
234 int compareStringCase(const __FlashStringHelper* a, const String& b) {
235  return -compareStringCase(b, a);
236 }
237 
238 // On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
239 // memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
240 // optimizing for 4-byte alignment here.
241 int compareStringCase(const __FlashStringHelper* a,
242  const __FlashStringHelper* b) {
243  if (a == b) { return 0; }
244  if (a == nullptr) { return -1; }
245  if (b == nullptr) { return 1; }
246  const char* aa = reinterpret_cast<const char*>(a);
247  const char* bb = reinterpret_cast<const char*>(b);
248 
249  while (true) {
250  uint8_t ca = pgm_read_byte(aa);
251  uint8_t cb = pgm_read_byte(bb);
252  uint8_t la = tolower(ca);
253  uint8_t lb = tolower(cb);
254  if (la != lb) return (int) la - (int) lb;
255  if (ca == '\0') return 0;
256  aa++;
257  bb++;
258  }
259 }
260 
261 //---------------------------------------------------------------------------
262 // compareStringN
263 //---------------------------------------------------------------------------
264 
265 // We need compareStringN() to support only (const char*) and (const
266 // __FlashStringHelper*). And it turns out that compareStringN(a, b, N) ==
267 // -compareString(b, a, N).
268 
269 int compareStringN(const char* a, const char* b, size_t n) {
270  if (a == b) { return 0; }
271  if (a == nullptr) { return -1; }
272  if (b == nullptr) { return 1; }
273  return strncmp(a, b, n);
274 }
275 
276 int compareStringN(const char* a, const __FlashStringHelper* b, size_t n) {
277  if (a == (const char*) b) { return 0; }
278  if (a == nullptr) { return -1; }
279  if (b == nullptr) { return 1; }
280  return strncmp_P(a, (const char*) b, n);
281 }
282 
283 int compareStringN(const __FlashStringHelper* a, const char* b, size_t n) {
284  return -compareStringN(b, a, n);
285 }
286 
287 // On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
288 // memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
289 // optimizing for 4-byte alignment here.
290 int compareStringN(const __FlashStringHelper* a, const __FlashStringHelper* b,
291  size_t n) {
292  if (a == b) { return 0; }
293  if (a == nullptr) { return -1; }
294  if (b == nullptr) { return 1; }
295  const char* aa = reinterpret_cast<const char*>(a);
296  const char* bb = reinterpret_cast<const char*>(b);
297 
298  while (n > 0) {
299  uint8_t ca = pgm_read_byte(aa);
300  uint8_t cb = pgm_read_byte(bb);
301  if (ca != cb) return (int) ca - (int) cb;
302  if (ca == '\0') return 0;
303  aa++;
304  bb++;
305  n--;
306  }
307  return 0;
308 }
309 
310 //---------------------------------------------------------------------------
311 // compareSubstring(haystack, needle)
312 //---------------------------------------------------------------------------
313 
314 bool compareSubstring(const char* haystack, const char* needle) {
315  return strstr(haystack, needle) != nullptr;
316 }
317 
318 bool compareSubstring(const char* haystack, const String& needle) {
319  return strstr(haystack, needle.c_str()) != nullptr;
320 }
321 
322 bool compareSubstring(const char* haystack, const __FlashStringHelper* needle) {
323  return strstr_P(haystack, (const char*) needle) != nullptr;
324 }
325 
326 bool compareSubstring(const String& haystack, const char* needle) {
327  return strstr(haystack.c_str(), needle) != nullptr;
328 }
329 
330 bool compareSubstring(const String& haystack, const String& needle) {
331  return strstr(haystack.c_str(), needle.c_str()) != nullptr;
332 }
333 
334 bool compareSubstring(const String& haystack, const __FlashStringHelper* needle) {
335  return strstr(haystack.c_str(), (const char*) needle) != nullptr;
336 }
337 
338 // An inefficient O(M*N) implementation of strstr() for PROGMEM strings.
339 // The KMP algorithm
340 // https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm
341 // is faster, but this brute force implementation is probably good enough.
342 bool compareSubstring(
343  const __FlashStringHelper* haystack,
344  const char* needle) {
345 
346  const char* hay = (const char*) haystack;
347  for (uint8_t ch = pgm_read_byte(hay); ch != '\0'; hay++) {
348  const char* subhay = hay;
349  const char* subneedle = needle;
350  while (true) {
351  uint8_t chay = pgm_read_byte(subhay);
352  uint8_t cneedle = *subneedle;
353  if (cneedle == '\0') return true;
354  if (chay == '\0') return false;
355  if (chay != cneedle) break;
356  subhay++;
357  subneedle++;
358  }
359  }
360 
361  return false;
362 }
363 
364 bool compareSubstring(
365  const __FlashStringHelper* haystack,
366  const String& needle) {
367  return compareSubstring(haystack, needle.c_str());
368 }
369 
370 // An inefficient O(M*N) implementation of strstr() for PROGMEM strings.
371 // The KMP algorithm
372 // https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm
373 // is faster, but this brute force implementation is probably good enough.
374 bool compareSubstring(
375  const __FlashStringHelper* haystack,
376  const __FlashStringHelper* needle) {
377 
378  const char* hay = reinterpret_cast<const char*>(haystack);
379  for (uint8_t ch = pgm_read_byte(hay); ch != '\0'; hay++) {
380  const char* subhay = hay;
381  const char* subneedle = (const char*) needle;
382  while (true) {
383  uint8_t chay = pgm_read_byte(subhay);
384  uint8_t cneedle = pgm_read_byte(subneedle);
385  if (cneedle == '\0') return true;
386  if (chay == '\0') return false;
387  if (chay != cneedle) break;
388  subhay++;
389  subneedle++;
390  }
391  }
392 
393  return false;
394 }
395 
396 //---------------------------------------------------------------------------
397 // compareEqual()
398 //---------------------------------------------------------------------------
399 
400 bool compareEqual(bool a, bool b) {
401  return (a == b);
402 }
403 
404 bool compareEqual(char a, char b) {
405  return (a == b);
406 }
407 
408 bool compareEqual(int a, int b) {
409  return (a == b);
410 }
411 
412 bool compareEqual(unsigned int a, unsigned int b) {
413  return (a == b);
414 }
415 
416 bool compareEqual(long a, long b) {
417  return (a == b);
418 }
419 
420 bool compareEqual(unsigned long a, unsigned long b) {
421  return (a == b);
422 }
423 
424 bool compareEqual(long long a, long long b) {
425  return (a == b);
426 }
427 
428 bool compareEqual(unsigned long long a, unsigned long long b) {
429  return (a == b);
430 }
431 
432 bool compareEqual(double a, double b) {
433  return (a == b);
434 }
435 
436 bool compareEqual(const void* a, const void* b) {
437  return (a == b);
438 }
439 
440 bool compareEqual(const char* a, const char* b) {
441  return compareString(a, b) == 0;
442 }
443 
444 bool compareEqual(const char* a, const String& b) {
445  return compareString(a, b) == 0;
446 }
447 
448 bool compareEqual(const char* a, const __FlashStringHelper* b) {
449  return compareString(a, b) == 0;
450 }
451 
452 bool compareEqual(const __FlashStringHelper* a, const char* b) {
453  return compareString(a, b) == 0;
454 }
455 
456 bool compareEqual(const __FlashStringHelper* a, const __FlashStringHelper* b) {
457  return compareString(a, b) == 0;
458 }
459 
460 bool compareEqual(const __FlashStringHelper* a, const String& b) {
461  return compareString(a, b) == 0;
462 }
463 
464 bool compareEqual(const String& a, const char* b) {
465  return compareString(a, b) == 0;
466 }
467 
468 bool compareEqual(const String& a, const String& b) {
469  return compareString(a, b) == 0;
470 }
471 
472 bool compareEqual(const String& a, const __FlashStringHelper* b) {
473  return compareString(a, b) == 0;
474 }
475 
476 //---------------------------------------------------------------------------
477 // compareLess()
478 //---------------------------------------------------------------------------
479 
480 bool compareLess(bool a, bool b) {
481  return (a < b);
482 }
483 
484 bool compareLess(char a, char b) {
485  return (a < b);
486 }
487 
488 bool compareLess(int a, int b) {
489  return (a < b);
490 }
491 
492 bool compareLess(unsigned int a, unsigned int b) {
493  return (a < b);
494 }
495 
496 bool compareLess(long a, long b) {
497  return (a < b);
498 }
499 
500 bool compareLess(unsigned long a, unsigned long b) {
501  return (a < b);
502 }
503 
504 bool compareLess(long long a, long long b) {
505  return (a < b);
506 }
507 
508 bool compareLess(unsigned long long a, unsigned long long b) {
509  return (a < b);
510 }
511 
512 bool compareLess(double a, double b) {
513  return (a < b);
514 }
515 
516 bool compareLess(const char* a, const char* b) {
517  return compareString(a, b) < 0;
518 }
519 
520 bool compareLess(const char* a, const String& b) {
521  return compareString(a, b) < 0;
522 }
523 
524 bool compareLess(const char* a, const __FlashStringHelper* b) {
525  return compareString(a, b) < 0;
526 }
527 
528 bool compareLess(const __FlashStringHelper* a, const char* b) {
529  return compareString(a, b) < 0;
530 }
531 
532 bool compareLess(
533  const __FlashStringHelper* a, const __FlashStringHelper* b) {
534  return compareString(a, b) < 0;
535 }
536 
537 bool compareLess(const __FlashStringHelper* a, const String& b) {
538  return compareString(a, b) < 0;
539 }
540 
541 bool compareLess(const String& a, const char* b) {
542  return compareString(a, b) < 0;
543 }
544 
545 bool compareLess(const String& a, const String& b) {
546  return compareString(a, b) < 0;
547 }
548 
549 bool compareLess(const String& a, const __FlashStringHelper* b) {
550  return compareString(a, b) < 0;
551 }
552 
553 //---------------------------------------------------------------------------
554 // compareMore()
555 //---------------------------------------------------------------------------
556 
557 bool compareMore(bool a, bool b) {
558  return (a > b);
559 }
560 
561 bool compareMore(char a, char b) {
562  return (a > b);
563 }
564 
565 bool compareMore(int a, int b) {
566  return (a > b);
567 }
568 
569 bool compareMore(unsigned int a, unsigned int b) {
570  return (a > b);
571 }
572 
573 bool compareMore(long a, long b) {
574  return (a > b);
575 }
576 
577 bool compareMore(unsigned long a, unsigned long b) {
578  return (a > b);
579 }
580 
581 bool compareMore(long long a, long long b) {
582  return (a > b);
583 }
584 
585 bool compareMore(unsigned long long a, unsigned long long b) {
586  return (a > b);
587 }
588 
589 bool compareMore(double a, double b) {
590  return (a > b);
591 }
592 
593 bool compareMore(const char* a, const char* b) {
594  return compareString(a, b) > 0;
595 }
596 
597 bool compareMore(const char* a, const String& b) {
598  return compareString(a, b) > 0;
599 }
600 
601 bool compareMore(const char* a, const __FlashStringHelper* b) {
602  return compareString(a, b) > 0;
603 }
604 
605 bool compareMore(const __FlashStringHelper* a, const char* b) {
606  return compareString(a, b) > 0;
607 }
608 
609 bool compareMore(const __FlashStringHelper* a, const __FlashStringHelper* b) {
610  return compareString(a, b) > 0;
611 }
612 
613 bool compareMore(const __FlashStringHelper* a, const String& b) {
614  return compareString(a, b) > 0;
615 }
616 
617 bool compareMore(const String& a, const char* b) {
618  return compareString(a, b) > 0;
619 }
620 
621 bool compareMore(const String& a, const String& b) {
622  return compareString(a, b) > 0;
623 }
624 
625 bool compareMore(const String& a, const __FlashStringHelper* b) {
626  return compareString(a, b) > 0;
627 }
628 
629 //---------------------------------------------------------------------------
630 // compareLessOrEqual
631 //---------------------------------------------------------------------------
632 
633 bool compareLessOrEqual(bool a, bool b) {
634  return (a <= b);
635 }
636 
637 bool compareLessOrEqual(char a, char b) {
638  return (a <= b);
639 }
640 
641 bool compareLessOrEqual(int a, int b) {
642  return (a <= b);
643 }
644 
645 bool compareLessOrEqual(unsigned int a, unsigned int b) {
646  return (a <= b);
647 }
648 
649 bool compareLessOrEqual(long a, long b) {
650  return (a <= b);
651 }
652 
653 bool compareLessOrEqual(unsigned long a, unsigned long b) {
654  return (a <= b);
655 }
656 
657 bool compareLessOrEqual(long long a, long long b) {
658  return (a <= b);
659 }
660 
661 bool compareLessOrEqual(unsigned long long a, unsigned long long b) {
662  return (a <= b);
663 }
664 
665 bool compareLessOrEqual(double a, double b) {
666  return (a <= b);
667 }
668 
669 bool compareLessOrEqual(const char* a, const char* b) {
670  return compareString(a, b) <= 0;
671 }
672 
673 bool compareLessOrEqual(const char* a, const String& b) {
674  return compareString(a, b) <= 0;
675 }
676 
677 bool compareLessOrEqual(const char* a, const __FlashStringHelper* b) {
678  return compareString(a, b) <= 0;
679 }
680 
681 bool compareLessOrEqual(const __FlashStringHelper* a, const char* b) {
682  return compareString(a, b) <= 0;
683 }
684 
685 bool compareLessOrEqual(
686  const __FlashStringHelper* a, const __FlashStringHelper* b) {
687  return compareString(a, b) <= 0;
688 }
689 
690 bool compareLessOrEqual(const __FlashStringHelper* a, const String& b) {
691  return compareString(a, b) <= 0;
692 }
693 
694 bool compareLessOrEqual(const String& a, const char* b) {
695  return compareString(a, b) <= 0;
696 }
697 
698 bool compareLessOrEqual(const String& a, const String& b) {
699  return compareString(a, b) <= 0;
700 }
701 
702 bool compareLessOrEqual(const String& a, const __FlashStringHelper* b) {
703  return compareString(a, b) <= 0;
704 }
705 
706 //---------------------------------------------------------------------------
707 // compareMoreOrEqual
708 //---------------------------------------------------------------------------
709 
710 bool compareMoreOrEqual(bool a, bool b) {
711  return (a >= b);
712 }
713 
714 bool compareMoreOrEqual(char a, char b) {
715  return (a >= b);
716 }
717 
718 bool compareMoreOrEqual(int a, int b) {
719  return (a >= b);
720 }
721 
722 bool compareMoreOrEqual(unsigned int a, unsigned int b) {
723  return (a >= b);
724 }
725 
726 bool compareMoreOrEqual(long a, long b) {
727  return (a >= b);
728 }
729 
730 bool compareMoreOrEqual(unsigned long a, unsigned long b) {
731  return (a >= b);
732 }
733 
734 bool compareMoreOrEqual(long long a, long long b) {
735  return (a >= b);
736 }
737 
738 bool compareMoreOrEqual(unsigned long long a, unsigned long long b) {
739  return (a >= b);
740 }
741 
742 bool compareMoreOrEqual(double a, double b) {
743  return (a >= b);
744 }
745 
746 bool compareMoreOrEqual(const char* a, const char* b) {
747  return compareString(a, b) >= 0;
748 }
749 
750 bool compareMoreOrEqual(const char* a, const String& b) {
751  return compareString(a, b) >= 0;
752 }
753 
754 bool compareMoreOrEqual(const char* a, const __FlashStringHelper* b) {
755  return compareString(a, b) >= 0;
756 }
757 
758 bool compareMoreOrEqual(const __FlashStringHelper* a, const char* b) {
759  return compareString(a, b) >= 0;
760 }
761 
762 bool compareMoreOrEqual(
763  const __FlashStringHelper* a, const __FlashStringHelper* b) {
764  return compareString(a, b) >= 0;
765 }
766 
767 bool compareMoreOrEqual(const __FlashStringHelper* a, const String& b) {
768  return compareString(a, b) >= 0;
769 }
770 
771 bool compareMoreOrEqual(const String& a, const char* b) {
772  return compareString(a, b) >= 0;
773 }
774 
775 bool compareMoreOrEqual(const String& a, const String& b) {
776  return compareString(a, b) >= 0;
777 }
778 
779 bool compareMoreOrEqual(const String& a, const __FlashStringHelper* b) {
780  return compareString(a, b) >= 0;
781 }
782 
783 //---------------------------------------------------------------------------
784 // compareNotEqual
785 //---------------------------------------------------------------------------
786 
787 bool compareNotEqual(bool a, bool b) {
788  return (a != b);
789 }
790 
791 bool compareNotEqual(char a, char b) {
792  return (a != b);
793 }
794 
795 bool compareNotEqual(int a, int b) {
796  return (a != b);
797 }
798 
799 bool compareNotEqual(unsigned int a, unsigned int b) {
800  return (a != b);
801 }
802 
803 bool compareNotEqual(long a, long b) {
804  return (a != b);
805 }
806 
807 bool compareNotEqual(unsigned long a, unsigned long b) {
808  return (a != b);
809 }
810 
811 bool compareNotEqual(long long a, long long b) {
812  return (a != b);
813 }
814 
815 bool compareNotEqual(unsigned long long a, unsigned long long b) {
816  return (a != b);
817 }
818 
819 bool compareNotEqual(double a, double b) {
820  return (a != b);
821 }
822 
823 bool compareNotEqual(const void* a, const void* b) {
824  return (a != b);
825 }
826 
827 bool compareNotEqual(const char* a, const char* b) {
828  return compareString(a, b) != 0;
829 }
830 
831 bool compareNotEqual(const char* a, const String& b) {
832  return compareString(a, b) != 0;
833 }
834 
835 bool compareNotEqual(const char* a, const __FlashStringHelper* b) {
836  return compareString(a, b) != 0;
837 }
838 
839 bool compareNotEqual(const __FlashStringHelper* a, const char* b) {
840  return compareString(a, b) != 0;
841 }
842 
843 bool compareNotEqual(
844  const __FlashStringHelper* a, const __FlashStringHelper* b) {
845  return compareString(a, b) != 0;
846 }
847 
848 bool compareNotEqual(const __FlashStringHelper* a, const String& b) {
849  return compareString(a, b) != 0;
850 }
851 
852 bool compareNotEqual(const String& a, const char* b) {
853  return compareString(a, b) != 0;
854 }
855 
856 bool compareNotEqual(const String& a, const String& b) {
857  return compareString(a, b) != 0;
858 }
859 
860 bool compareNotEqual(const String& a, const __FlashStringHelper* b) {
861  return compareString(a, b) != 0;
862 }
863 
864 //---------------------------------------------------------------------------
865 // compareStringCaseEqual()
866 //---------------------------------------------------------------------------
867 
868 bool compareStringCaseEqual(const char* a, const char* b) {
869  return compareStringCase(a, b) == 0;
870 }
871 
872 bool compareStringCaseEqual(const char* a, const String& b) {
873  return compareStringCase(a, b) == 0;
874 }
875 
876 bool compareStringCaseEqual(const char* a, const __FlashStringHelper* b) {
877  return compareStringCase(a, b) == 0;
878 }
879 
880 bool compareStringCaseEqual(const __FlashStringHelper* a, const char* b) {
881  return compareStringCase(a, b) == 0;
882 }
883 
884 bool compareStringCaseEqual(const __FlashStringHelper* a,
885  const __FlashStringHelper* b) {
886  return compareStringCase(a, b) == 0;
887 }
888 
889 bool compareStringCaseEqual(const __FlashStringHelper* a, const String& b) {
890  return compareStringCase(a, b) == 0;
891 }
892 
893 bool compareStringCaseEqual(const String& a, const char* b) {
894  return compareStringCase(a, b) == 0;
895 }
896 
897 bool compareStringCaseEqual(const String& a, const String& b) {
898  return compareStringCase(a, b) == 0;
899 }
900 
901 bool compareStringCaseEqual(const String& a, const __FlashStringHelper* b) {
902  return compareStringCase(a, b) == 0;
903 }
904 
905 //---------------------------------------------------------------------------
906 // compareStringCaseNotEqual()
907 //---------------------------------------------------------------------------
908 
909 bool compareStringCaseNotEqual(const char* a, const char* b) {
910  return compareStringCase(a, b) != 0;
911 }
912 
913 bool compareStringCaseNotEqual(const char* a, const String& b) {
914  return compareStringCase(a, b) != 0;
915 }
916 
917 bool compareStringCaseNotEqual(const char* a, const __FlashStringHelper* b) {
918  return compareStringCase(a, b) != 0;
919 }
920 
921 bool compareStringCaseNotEqual(const __FlashStringHelper* a, const char* b) {
922  return compareStringCase(a, b) != 0;
923 }
924 
925 bool compareStringCaseNotEqual(const __FlashStringHelper* a,
926  const __FlashStringHelper* b) {
927  return compareStringCase(a, b) != 0;
928 }
929 
930 bool compareStringCaseNotEqual(const __FlashStringHelper* a, const String& b) {
931  return compareStringCase(a, b) != 0;
932 }
933 
934 bool compareStringCaseNotEqual(const String& a, const char* b) {
935  return compareStringCase(a, b) != 0;
936 }
937 
938 bool compareStringCaseNotEqual(const String& a, const String& b) {
939  return compareStringCase(a, b) != 0;
940 }
941 
942 bool compareStringCaseNotEqual(const String& a, const __FlashStringHelper* b) {
943  return compareStringCase(a, b) != 0;
944 }
945 
946 //---------------------------------------------------------------------------
947 // compareNear()
948 //---------------------------------------------------------------------------
949 
950 bool compareNear(int a, int b, int error) {
951  return abs(a - b) <= error;
952 }
953 
954 bool compareNear(unsigned int a, unsigned int b, unsigned int error) {
955  return (unsigned int) abs((int)(a - b)) <= error;
956 }
957 
958 bool compareNear(long a, long b, long error) {
959  return abs(a - b) <= error;
960 }
961 
962 bool compareNear(unsigned long a, unsigned long b, unsigned long error) {
963  return (unsigned long) abs((long)(a - b)) <= error;
964 }
965 
966 bool compareNear(double a, double b, double error) {
967  return fabs(a - b) <= error;
968 }
969 
970 bool compareNotNear(int a, int b, int error) {
971  return !compareNear(a, b, error);
972 }
973 
974 bool compareNotNear(unsigned int a, unsigned int b, unsigned int error) {
975  return !compareNear(a, b, error);
976 }
977 
978 bool compareNotNear(long a, long b, long error) {
979  return !compareNear(a, b, error);
980 }
981 
982 bool compareNotNear(unsigned long a, unsigned long b, unsigned long error) {
983  return !compareNear(a, b, error);
984 }
985 
986 bool compareNotNear(double a, double b, double error) {
987  return !compareNear(a, b, error);
988 }
989 
990 }
991 }
This file provides overloaded compareXxx(a, b) functions which are used by the various assertXxx(a,...
Various macros to smooth over the differences among the various platforms with regards to their suppo...