AUnit  1.3
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 // compareEqual()
312 //---------------------------------------------------------------------------
313 
314 bool compareEqual(bool a, bool b) {
315  return (a == b);
316 }
317 
318 bool compareEqual(char a, char b) {
319  return (a == b);
320 }
321 
322 bool compareEqual(int a, int b) {
323  return (a == b);
324 }
325 
326 bool compareEqual(unsigned int a, unsigned int b) {
327  return (a == b);
328 }
329 
330 bool compareEqual(long a, long b) {
331  return (a == b);
332 }
333 
334 bool compareEqual(unsigned long a, unsigned long b) {
335  return (a == b);
336 }
337 
338 bool compareEqual(long long a, long long b) {
339  return (a == b);
340 }
341 
342 bool compareEqual(unsigned long long a, unsigned long long b) {
343  return (a == b);
344 }
345 
346 bool compareEqual(double a, double b) {
347  return (a == b);
348 }
349 
350 bool compareEqual(const char* a, const char* b) {
351  return compareString(a, b) == 0;
352 }
353 
354 bool compareEqual(const char* a, const String& b) {
355  return compareString(a, b) == 0;
356 }
357 
358 bool compareEqual(const char* a, const __FlashStringHelper* b) {
359  return compareString(a, b) == 0;
360 }
361 
362 bool compareEqual(const __FlashStringHelper* a, const char* b) {
363  return compareString(a, b) == 0;
364 }
365 
366 bool compareEqual(const __FlashStringHelper* a, const __FlashStringHelper* b) {
367  return compareString(a, b) == 0;
368 }
369 
370 bool compareEqual(const __FlashStringHelper* a, const String& b) {
371  return compareString(a, b) == 0;
372 }
373 
374 bool compareEqual(const String& a, const char* b) {
375  return compareString(a, b) == 0;
376 }
377 
378 bool compareEqual(const String& a, const String& b) {
379  return compareString(a, b) == 0;
380 }
381 
382 bool compareEqual(const String& a, const __FlashStringHelper* b) {
383  return compareString(a, b) == 0;
384 }
385 
386 //---------------------------------------------------------------------------
387 // compareLess()
388 //---------------------------------------------------------------------------
389 
390 bool compareLess(bool a, bool b) {
391  return (a < b);
392 }
393 
394 bool compareLess(char a, char b) {
395  return (a < b);
396 }
397 
398 bool compareLess(int a, int b) {
399  return (a < b);
400 }
401 
402 bool compareLess(unsigned int a, unsigned int b) {
403  return (a < b);
404 }
405 
406 bool compareLess(long a, long b) {
407  return (a < b);
408 }
409 
410 bool compareLess(unsigned long a, unsigned long b) {
411  return (a < b);
412 }
413 
414 bool compareLess(long long a, long long b) {
415  return (a < b);
416 }
417 
418 bool compareLess(unsigned long long a, unsigned long long b) {
419  return (a < b);
420 }
421 
422 bool compareLess(double a, double b) {
423  return (a < b);
424 }
425 
426 bool compareLess(const char* a, const char* b) {
427  return compareString(a, b) < 0;
428 }
429 
430 bool compareLess(const char* a, const String& b) {
431  return compareString(a, b) < 0;
432 }
433 
434 bool compareLess(const char* a, const __FlashStringHelper* b) {
435  return compareString(a, b) < 0;
436 }
437 
438 bool compareLess(const __FlashStringHelper* a, const char* b) {
439  return compareString(a, b) < 0;
440 }
441 
442 bool compareLess(
443  const __FlashStringHelper* a, const __FlashStringHelper* b) {
444  return compareString(a, b) < 0;
445 }
446 
447 bool compareLess(const __FlashStringHelper* a, const String& b) {
448  return compareString(a, b) < 0;
449 }
450 
451 bool compareLess(const String& a, const char* b) {
452  return compareString(a, b) < 0;
453 }
454 
455 bool compareLess(const String& a, const String& b) {
456  return compareString(a, b) < 0;
457 }
458 
459 bool compareLess(const String& a, const __FlashStringHelper* b) {
460  return compareString(a, b) < 0;
461 }
462 
463 //---------------------------------------------------------------------------
464 // compareMore()
465 //---------------------------------------------------------------------------
466 
467 bool compareMore(bool a, bool b) {
468  return (a > b);
469 }
470 
471 bool compareMore(char a, char b) {
472  return (a > b);
473 }
474 
475 bool compareMore(int a, int b) {
476  return (a > b);
477 }
478 
479 bool compareMore(unsigned int a, unsigned int b) {
480  return (a > b);
481 }
482 
483 bool compareMore(long a, long b) {
484  return (a > b);
485 }
486 
487 bool compareMore(unsigned long a, unsigned long b) {
488  return (a > b);
489 }
490 
491 bool compareMore(long long a, long long b) {
492  return (a > b);
493 }
494 
495 bool compareMore(unsigned long long a, unsigned long long b) {
496  return (a > b);
497 }
498 
499 bool compareMore(double a, double b) {
500  return (a > b);
501 }
502 
503 bool compareMore(const char* a, const char* b) {
504  return compareString(a, b) > 0;
505 }
506 
507 bool compareMore(const char* a, const String& b) {
508  return compareString(a, b) > 0;
509 }
510 
511 bool compareMore(const char* a, const __FlashStringHelper* b) {
512  return compareString(a, b) > 0;
513 }
514 
515 bool compareMore(const __FlashStringHelper* a, const char* b) {
516  return compareString(a, b) > 0;
517 }
518 
519 bool compareMore(const __FlashStringHelper* a, const __FlashStringHelper* b) {
520  return compareString(a, b) > 0;
521 }
522 
523 bool compareMore(const __FlashStringHelper* a, const String& b) {
524  return compareString(a, b) > 0;
525 }
526 
527 bool compareMore(const String& a, const char* b) {
528  return compareString(a, b) > 0;
529 }
530 
531 bool compareMore(const String& a, const String& b) {
532  return compareString(a, b) > 0;
533 }
534 
535 bool compareMore(const String& a, const __FlashStringHelper* b) {
536  return compareString(a, b) > 0;
537 }
538 
539 //---------------------------------------------------------------------------
540 // compareLessOrEqual
541 //---------------------------------------------------------------------------
542 
543 bool compareLessOrEqual(bool a, bool b) {
544  return (a <= b);
545 }
546 
547 bool compareLessOrEqual(char a, char b) {
548  return (a <= b);
549 }
550 
551 bool compareLessOrEqual(int a, int b) {
552  return (a <= b);
553 }
554 
555 bool compareLessOrEqual(unsigned int a, unsigned int b) {
556  return (a <= b);
557 }
558 
559 bool compareLessOrEqual(long a, long b) {
560  return (a <= b);
561 }
562 
563 bool compareLessOrEqual(unsigned long a, unsigned long b) {
564  return (a <= b);
565 }
566 
567 bool compareLessOrEqual(long long a, long long b) {
568  return (a <= b);
569 }
570 
571 bool compareLessOrEqual(unsigned long long a, unsigned long long b) {
572  return (a <= b);
573 }
574 
575 bool compareLessOrEqual(double a, double b) {
576  return (a <= b);
577 }
578 
579 bool compareLessOrEqual(const char* a, const char* b) {
580  return compareString(a, b) <= 0;
581 }
582 
583 bool compareLessOrEqual(const char* a, const String& b) {
584  return compareString(a, b) <= 0;
585 }
586 
587 bool compareLessOrEqual(const char* a, const __FlashStringHelper* b) {
588  return compareString(a, b) <= 0;
589 }
590 
591 bool compareLessOrEqual(const __FlashStringHelper* a, const char* b) {
592  return compareString(a, b) <= 0;
593 }
594 
595 bool compareLessOrEqual(
596  const __FlashStringHelper* a, const __FlashStringHelper* b) {
597  return compareString(a, b) <= 0;
598 }
599 
600 bool compareLessOrEqual(const __FlashStringHelper* a, const String& b) {
601  return compareString(a, b) <= 0;
602 }
603 
604 bool compareLessOrEqual(const String& a, const char* b) {
605  return compareString(a, b) <= 0;
606 }
607 
608 bool compareLessOrEqual(const String& a, const String& b) {
609  return compareString(a, b) <= 0;
610 }
611 
612 bool compareLessOrEqual(const String& a, const __FlashStringHelper* b) {
613  return compareString(a, b) <= 0;
614 }
615 
616 //---------------------------------------------------------------------------
617 // compareMoreOrEqual
618 //---------------------------------------------------------------------------
619 
620 bool compareMoreOrEqual(bool a, bool b) {
621  return (a >= b);
622 }
623 
624 bool compareMoreOrEqual(char a, char b) {
625  return (a >= b);
626 }
627 
628 bool compareMoreOrEqual(int a, int b) {
629  return (a >= b);
630 }
631 
632 bool compareMoreOrEqual(unsigned int a, unsigned int b) {
633  return (a >= b);
634 }
635 
636 bool compareMoreOrEqual(long a, long b) {
637  return (a >= b);
638 }
639 
640 bool compareMoreOrEqual(unsigned long a, unsigned long b) {
641  return (a >= b);
642 }
643 
644 bool compareMoreOrEqual(long long a, long long b) {
645  return (a >= b);
646 }
647 
648 bool compareMoreOrEqual(unsigned long long a, unsigned long long b) {
649  return (a >= b);
650 }
651 
652 bool compareMoreOrEqual(double a, double b) {
653  return (a >= b);
654 }
655 
656 bool compareMoreOrEqual(const char* a, const char* b) {
657  return compareString(a, b) >= 0;
658 }
659 
660 bool compareMoreOrEqual(const char* a, const String& b) {
661  return compareString(a, b) >= 0;
662 }
663 
664 bool compareMoreOrEqual(const char* a, const __FlashStringHelper* b) {
665  return compareString(a, b) >= 0;
666 }
667 
668 bool compareMoreOrEqual(const __FlashStringHelper* a, const char* b) {
669  return compareString(a, b) >= 0;
670 }
671 
672 bool compareMoreOrEqual(
673  const __FlashStringHelper* a, const __FlashStringHelper* b) {
674  return compareString(a, b) >= 0;
675 }
676 
677 bool compareMoreOrEqual(const __FlashStringHelper* a, const String& b) {
678  return compareString(a, b) >= 0;
679 }
680 
681 bool compareMoreOrEqual(const String& a, const char* b) {
682  return compareString(a, b) >= 0;
683 }
684 
685 bool compareMoreOrEqual(const String& a, const String& b) {
686  return compareString(a, b) >= 0;
687 }
688 
689 bool compareMoreOrEqual(const String& a, const __FlashStringHelper* b) {
690  return compareString(a, b) >= 0;
691 }
692 
693 //---------------------------------------------------------------------------
694 // compareNotEqual
695 //---------------------------------------------------------------------------
696 
697 bool compareNotEqual(bool a, bool b) {
698  return (a != b);
699 }
700 
701 bool compareNotEqual(char a, char b) {
702  return (a != b);
703 }
704 
705 bool compareNotEqual(int a, int b) {
706  return (a != b);
707 }
708 
709 bool compareNotEqual(unsigned int a, unsigned int b) {
710  return (a != b);
711 }
712 
713 bool compareNotEqual(long a, long b) {
714  return (a != b);
715 }
716 
717 bool compareNotEqual(unsigned long a, unsigned long b) {
718  return (a != b);
719 }
720 
721 bool compareNotEqual(long long a, long long b) {
722  return (a != b);
723 }
724 
725 bool compareNotEqual(unsigned long long a, unsigned long long b) {
726  return (a != b);
727 }
728 
729 bool compareNotEqual(double a, double b) {
730  return (a != b);
731 }
732 
733 bool compareNotEqual(const char* a, const char* b) {
734  return compareString(a, b) != 0;
735 }
736 
737 bool compareNotEqual(const char* a, const String& b) {
738  return compareString(a, b) != 0;
739 }
740 
741 bool compareNotEqual(const char* a, const __FlashStringHelper* b) {
742  return compareString(a, b) != 0;
743 }
744 
745 bool compareNotEqual(const __FlashStringHelper* a, const char* b) {
746  return compareString(a, b) != 0;
747 }
748 
749 bool compareNotEqual(
750  const __FlashStringHelper* a, const __FlashStringHelper* b) {
751  return compareString(a, b) != 0;
752 }
753 
754 bool compareNotEqual(const __FlashStringHelper* a, const String& b) {
755  return compareString(a, b) != 0;
756 }
757 
758 bool compareNotEqual(const String& a, const char* b) {
759  return compareString(a, b) != 0;
760 }
761 
762 bool compareNotEqual(const String& a, const String& b) {
763  return compareString(a, b) != 0;
764 }
765 
766 bool compareNotEqual(const String& a, const __FlashStringHelper* b) {
767  return compareString(a, b) != 0;
768 }
769 
770 //---------------------------------------------------------------------------
771 // compareStringCaseEqual()
772 //---------------------------------------------------------------------------
773 
774 bool compareStringCaseEqual(const char* a, const char* b) {
775  return compareStringCase(a, b) == 0;
776 }
777 
778 bool compareStringCaseEqual(const char* a, const String& b) {
779  return compareStringCase(a, b) == 0;
780 }
781 
782 bool compareStringCaseEqual(const char* a, const __FlashStringHelper* b) {
783  return compareStringCase(a, b) == 0;
784 }
785 
786 bool compareStringCaseEqual(const __FlashStringHelper* a, const char* b) {
787  return compareStringCase(a, b) == 0;
788 }
789 
790 bool compareStringCaseEqual(const __FlashStringHelper* a,
791  const __FlashStringHelper* b) {
792  return compareStringCase(a, b) == 0;
793 }
794 
795 bool compareStringCaseEqual(const __FlashStringHelper* a, const String& b) {
796  return compareStringCase(a, b) == 0;
797 }
798 
799 bool compareStringCaseEqual(const String& a, const char* b) {
800  return compareStringCase(a, b) == 0;
801 }
802 
803 bool compareStringCaseEqual(const String& a, const String& b) {
804  return compareStringCase(a, b) == 0;
805 }
806 
807 bool compareStringCaseEqual(const String& a, const __FlashStringHelper* b) {
808  return compareStringCase(a, b) == 0;
809 }
810 
811 //---------------------------------------------------------------------------
812 // compareStringCaseNotEqual()
813 //---------------------------------------------------------------------------
814 
815 bool compareStringCaseNotEqual(const char* a, const char* b) {
816  return compareStringCase(a, b) != 0;
817 }
818 
819 bool compareStringCaseNotEqual(const char* a, const String& b) {
820  return compareStringCase(a, b) != 0;
821 }
822 
823 bool compareStringCaseNotEqual(const char* a, const __FlashStringHelper* b) {
824  return compareStringCase(a, b) != 0;
825 }
826 
827 bool compareStringCaseNotEqual(const __FlashStringHelper* a, const char* b) {
828  return compareStringCase(a, b) != 0;
829 }
830 
831 bool compareStringCaseNotEqual(const __FlashStringHelper* a,
832  const __FlashStringHelper* b) {
833  return compareStringCase(a, b) != 0;
834 }
835 
836 bool compareStringCaseNotEqual(const __FlashStringHelper* a, const String& b) {
837  return compareStringCase(a, b) != 0;
838 }
839 
840 bool compareStringCaseNotEqual(const String& a, const char* b) {
841  return compareStringCase(a, b) != 0;
842 }
843 
844 bool compareStringCaseNotEqual(const String& a, const String& b) {
845  return compareStringCase(a, b) != 0;
846 }
847 
848 bool compareStringCaseNotEqual(const String& a, const __FlashStringHelper* b) {
849  return compareStringCase(a, b) != 0;
850 }
851 
852 //---------------------------------------------------------------------------
853 // compareNear()
854 //---------------------------------------------------------------------------
855 
856 bool compareNear(int a, int b, int error) {
857  return abs(a - b) <= error;
858 }
859 
860 bool compareNear(unsigned int a, unsigned int b, unsigned int error) {
861  return (unsigned int) abs((int)(a - b)) <= error;
862 }
863 
864 bool compareNear(long a, long b, long error) {
865  return abs(a - b) <= error;
866 }
867 
868 bool compareNear(unsigned long a, unsigned long b, unsigned long error) {
869  return (unsigned long) abs((long)(a - b)) <= error;
870 }
871 
872 bool compareNear(double a, double b, double error) {
873  return fabs(a - b) <= error;
874 }
875 
876 bool compareNotNear(int a, int b, int error) {
877  return !compareNear(a, b, error);
878 }
879 
880 bool compareNotNear(unsigned int a, unsigned int b, unsigned int error) {
881  return !compareNear(a, b, error);
882 }
883 
884 bool compareNotNear(long a, long b, long error) {
885  return !compareNear(a, b, error);
886 }
887 
888 bool compareNotNear(unsigned long a, unsigned long b, unsigned long error) {
889  return !compareNear(a, b, error);
890 }
891 
892 bool compareNotNear(double a, double b, double error) {
893  return !compareNear(a, b, error);
894 }
895 
896 }
897 }
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...