gitout

A static git page generator
git clone https://git.bracken.jp/gitout.git
Log | Files | Refs | README | LICENSE

side_effects.cpp (4595B)


      1 // This is free and unencumbered software released into the public domain.
      2 //
      3 // Anyone is free to copy, modify, publish, use, compile, sell, or
      4 // distribute this software, either in source code form or as a compiled
      5 // binary, for any purpose, commercial or non-commercial, and by any
      6 // means.
      7 //
      8 // In jurisdictions that recognize copyright laws, the author or authors
      9 // of this software dedicate any and all copyright interest in the
     10 // software to the public domain. We make this dedication for the benefit
     11 // of the public at large and to the detriment of our heirs and
     12 // successors. We intend this dedication to be an overt act of
     13 // relinquishment in perpetuity of all present and future rights to this
     14 // software under copyright law.
     15 //
     16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     19 // IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22 // OTHER DEALINGS IN THE SOFTWARE.
     23 //
     24 // For more information, please refer to <http://unlicense.org/>
     25 
     26 #include "utest.h"
     27 
     28 struct reader {
     29   int offset;
     30 };
     31 
     32 static int next(struct reader *reader) {
     33   const int current = reader->offset;
     34   reader->offset += 1;
     35   return current;
     36 }
     37 
     38 static const int bools[20] = {0, 1, 0, 1};
     39 static const int ints[20] = {42, 13, 6, -53};
     40 static const char *const strings[20] = {"42", "13", "6", "-53"};
     41 
     42 UTEST(cpp_side_effects, EXPECT_TRUE_EXPECT_FALSE) {
     43   struct reader reader = {0};
     44   EXPECT_FALSE(bools[next(&reader)]);
     45   EXPECT_TRUE(bools[next(&reader)]);
     46   EXPECT_FALSE(bools[next(&reader)]);
     47   EXPECT_TRUE(bools[next(&reader)]);
     48 }
     49 
     50 UTEST(cpp_side_effects, EXPECT_EQ_EXPECT_NE) {
     51   struct reader reader = {0};
     52   EXPECT_EQ(42, ints[next(&reader)]);
     53   EXPECT_NE(14, ints[next(&reader)]);
     54   EXPECT_EQ(6, ints[next(&reader)]);
     55   EXPECT_NE(52, ints[next(&reader)]);
     56 }
     57 
     58 UTEST(cpp_side_effects, EXPECT_LT_EXPECT_LE) {
     59   struct reader reader = {0};
     60   EXPECT_LT(41, ints[next(&reader)]);
     61   EXPECT_LE(13, ints[next(&reader)]);
     62   EXPECT_LT(5, ints[next(&reader)]);
     63   EXPECT_LE(-53, ints[next(&reader)]);
     64 }
     65 
     66 UTEST(cpp_side_effects, EXPECT_GT_EXPECT_GE) {
     67   struct reader reader = {0};
     68   EXPECT_GT(43, ints[next(&reader)]);
     69   EXPECT_GE(13, ints[next(&reader)]);
     70   EXPECT_GT(7, ints[next(&reader)]);
     71   EXPECT_GE(-53, ints[next(&reader)]);
     72 }
     73 
     74 UTEST(cpp_side_effects, EXPECT_STREQ_EXPECT_STRNE) {
     75   struct reader reader = {0};
     76   EXPECT_STRNE("!42", strings[next(&reader)]);
     77   EXPECT_STREQ("13", strings[next(&reader)]);
     78   EXPECT_STRNE("!6", strings[next(&reader)]);
     79   EXPECT_STREQ("-53", strings[next(&reader)]);
     80 }
     81 
     82 UTEST(cpp_side_effects, EXPECT_STRNEQ_EXPECT_STRNEQ) {
     83   struct reader reader = {0};
     84   EXPECT_STRNNE("!42", strings[next(&reader)], 3);
     85   EXPECT_STRNEQ("13", strings[next(&reader)], 2);
     86   EXPECT_STRNNE("!6", strings[next(&reader)], 2);
     87   EXPECT_STRNEQ("-53", strings[next(&reader)], 3);
     88 }
     89 
     90 UTEST(cpp_side_effects, ASSERT_TRUE_ASSERT_FALSE) {
     91   struct reader reader = {0};
     92   ASSERT_FALSE(bools[next(&reader)]);
     93   ASSERT_TRUE(bools[next(&reader)]);
     94   ASSERT_FALSE(bools[next(&reader)]);
     95   ASSERT_TRUE(bools[next(&reader)]);
     96 }
     97 
     98 UTEST(cpp_side_effects, ASSERT_EQ_ASSERT_NE) {
     99   struct reader reader = {0};
    100   ASSERT_EQ(42, ints[next(&reader)]);
    101   ASSERT_NE(14, ints[next(&reader)]);
    102   ASSERT_EQ(6, ints[next(&reader)]);
    103   ASSERT_NE(52, ints[next(&reader)]);
    104 }
    105 
    106 UTEST(cpp_side_effects, ASSERT_LT_ASSERT_LE) {
    107   struct reader reader = {0};
    108   ASSERT_LT(41, ints[next(&reader)]);
    109   ASSERT_LE(13, ints[next(&reader)]);
    110   ASSERT_LT(5, ints[next(&reader)]);
    111   ASSERT_LE(-53, ints[next(&reader)]);
    112 }
    113 
    114 UTEST(cpp_side_effects, ASSERT_GT_ASSERT_GE) {
    115   struct reader reader = {0};
    116   ASSERT_GT(43, ints[next(&reader)]);
    117   ASSERT_GE(13, ints[next(&reader)]);
    118   ASSERT_GT(7, ints[next(&reader)]);
    119   ASSERT_GE(-53, ints[next(&reader)]);
    120 }
    121 
    122 UTEST(cpp_side_effects, ASSERT_STREQ_ASSERT_STRNE) {
    123   struct reader reader = {0};
    124   ASSERT_STRNE("!42", strings[next(&reader)]);
    125   ASSERT_STREQ("13", strings[next(&reader)]);
    126   ASSERT_STRNE("!6", strings[next(&reader)]);
    127   ASSERT_STREQ("-53", strings[next(&reader)]);
    128 }
    129 
    130 UTEST(cpp_side_effects, ASSERT_STRNEQ_ASSERT_STRNEQ) {
    131   struct reader reader = {0};
    132   ASSERT_STRNNE("!42", strings[next(&reader)], 3);
    133   ASSERT_STRNEQ("13", strings[next(&reader)], 2);
    134   ASSERT_STRNNE("!6", strings[next(&reader)], 2);
    135   ASSERT_STRNEQ("-53", strings[next(&reader)], 3);
    136 }