gitout

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

side_effects.c (4569B)


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