source: branches/properties/SL/HEADERTESTS/tiny.cxx

Last change on this file was 18950, checked in by westram, 3 years ago
  • add header providing
    • stringize + concatenate.
    • their argument-prescan-versions stringize_pscan + concatenate_pscans.
  • add unittests for these macros.
File size: 2.2 KB
Line 
1// ========================================================= //
2//                                                           //
3//   File      : tiny.cxx                                    //
4//   Purpose   : misc tiny unittests                         //
5//                                                           //
6//   Coded by Ralf Westram (coder@reallysoft.de) in Jan 22   //
7//   http://www.arb-home.de/                                 //
8//                                                           //
9// ========================================================= //
10
11// --------------------------------------------------------------------------------
12
13#ifdef UNIT_TESTS
14#ifndef TEST_UNIT_H
15#include <test_unit.h>
16#endif
17
18#include <stringize.h>
19
20#undef  UNDEFINED
21#define DEFINED value
22
23void TEST_stringize() {
24    // for undefined ids, stringize and stringize_pscan produce the same text:
25    TEST_EXPECT_EQUAL(stringize      (UNDEFINED), "UNDEFINED");
26    TEST_EXPECT_EQUAL(stringize_pscan(UNDEFINED), "UNDEFINED");
27
28    // for defined ids, stringize_pscan inserts the defined value:
29    TEST_EXPECT_EQUAL(stringize      (DEFINED),   "DEFINED");
30    TEST_EXPECT_EQUAL(stringize_pscan(DEFINED),   "value");
31
32    const char *value = "variable content";
33
34    TEST_EXPECT_EQUAL(                concatenate(DE, FINED),  "variable content");
35    TEST_EXPECT_EQUAL(stringize      (concatenate(DE, FINED)), "concatenate(DE, FINED)");
36    TEST_EXPECT_EQUAL(stringize_pscan(concatenate(DE, FINED)), "value");
37
38    // TEST_EXPECT_EQUAL(concatenate(UNDE, FINED), "variable content"); // error: 'UNDEFINED' was not declared in this scope
39    TEST_EXPECT_EQUAL(stringize      (concatenate(UNDE, FINED)), "concatenate(UNDE, FINED)");
40    TEST_EXPECT_EQUAL(stringize_pscan(concatenate(UNDE, FINED)), "UNDEFINED");
41
42    const char *UNDEFINEDvalue = "value of UNDEFINEDvalue";
43    TEST_EXPECT_EQUAL(stringize_pscan   (concatenate(UNDEFINED,        DEFINED)), "UNDEFINEDDEFINED");
44    TEST_EXPECT_EQUAL(stringize_pscan   (concatenate_pscans(UNDEFINED, DEFINED)), "UNDEFINEDvalue");
45    TEST_EXPECT_EQUAL(                   concatenate_pscans(UNDEFINED, DEFINED),  "value of UNDEFINEDvalue");
46}
47
48#endif // UNIT_TESTS
49
50// --------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.