Debian Codegraph @

tests/message_formatting_tests.c

raw symbols SCIP
1 #cxx . . $ `<file>/tests/message_formatting_tests.c`/include <cgreen/cgreen.h>cxx . . $ `<file>/include/cgreen/cgreen.h`/
2 #include <cgreen/message_formatting.h>cxx . . $ `<file>/include/cgreen/message_formatting.h`/
3 #include <stdint.h>
4 #include <stdlib.h>
5 #include "src/constraint_internal.h"cxx . . $ `<file>/src/constraint_internal.h`/
6
7 #ifdef __cpluspluscxx . . $ `<built-in>:440:9`!
8 using namespace cgreen;
9 #endif
10
11 Describecxx . . $ CgreenContext#(MessageFormatting);
12 BeforeEachcxx . . $ `include/cgreen/unit.h:15:9`!(MessageFormatting) {}
13 AfterEachcxx . . $ AfterEach_For_MessageFormatting.(MessageFormatting) {}
14
15
16 Ensurecxx . . $ CgreenSpec__MessageFormatting__can_show_failure_message_containing_percent_sign__.(MessageFormatting, can_show_failure_message_containing_percent_sign) {
17 const char *string_with_percent = "This contains %!";
18 Constraintcxx . . $ Constraint# *constraint =
19 create_equal_to_string_constraintcxx . . $ create_equal_to_string_constraint(6f3cd94f7e4cc57).(string_with_percent, "string_with_percent");
20
21 char *failure_message = failure_message_forcxx . . $ failure_message_for(12dea272953de187).(constraint, "actual_string", (intptr_tcxx . . $ intptr_t#)"This contains another %!");
22 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(failure_message, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("contains %%!"));
23 assert_thatcxx . . $ cgreen/assert_that_(b064aa216885589).(failure_message, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("another %%!"));
24
25 constraint->destroycxx . . $ Constraint_#destroy.(constraint);
26 freecxx . . $ free(5d22bdacc48458e8).(failure_message);
27 }
28
29 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(MessageFormatting, shows_offset_as_zero_based) {
30 char actual_data[] = {0x0a, 0x0b, 0x0c, 0x0d};
31 char expected_data[] = {0x0b, 0x0b, 0x0c, 0x0d};
32 Constraintcxx . . $ Constraint# *constraint =
33 create_equal_to_contents_constraintcxx . . $ create_equal_to_contents_constraint(329cc2776ae464c5).(expected_data, 4, "expectd_data");
34
35 char *failure_message = failure_message_forcxx . . $ failure_message_for(12dea272953de187).(constraint, "actual_data", (intptr_tcxx . . $ intptr_t#)actual_data);
36 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(failure_message, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("at offset"));
37 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(failure_message, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("[0]"));
38 assert_thatcxx . . $ cgreen/(failure_message, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("actual value:"));
39 assert_thatcxx . . $ intptr_t#(failure_message, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("expected value:"));
40 assert_thatcxx . . $ cgreen/(strstr(failure_message, "actual"), is_less_thancxx . . $ `include/cgreen/constraint_syntax_helpers.h:36:9`!(strstr(failure_message, "expected")));
41 assert_thatcxx . . $ cgreen/assert_that_(b064aa216885589).(failure_message, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("0x0a"));
42 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(failure_message, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("0x0b"));
43 assert_thatcxx . . $ intptr_t#(strstr(failure_message, "0x0a"), is_less_thancxx . . $ `include/cgreen/constraint_syntax_helpers.h:36:9`!(strstr(failure_message, "0x0b")));
44
45 freecxx . . $ free(5d22bdacc48458e8).(failure_message);
46 destroy_constraintcxx . . $ destroy_constraint(f159a969fe179808).(constraint);
47 }
48
49 #if INTPTR_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:182:11`! > INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!
50 /* Only meaningful where intptr_t is wider than 32 bits: a constraint stores
51 integers as intptr_t, so a >32-bit value cannot exist on a 32-bit arch.
52 Pins the [0x%x]-vs-intptr_t truncation in is_equal_to_hex's failure message. */
53 Ensurecxx . . $ contextForMessageFormatting.(MessageFormatting, shows_full_width_hex_actual_value_without_truncation) {
54 Constraintcxx . . $ Constraint# *constraint =
55 create_equal_to_hexvalue_constraintcxx . . $ create_equal_to_hexvalue_constraint(f83092978cf2a14d).((intptr_tcxx . . $ intptr_t#)0xab, "expected_value");
56
57 char *failure_message =
58 failure_message_forcxx . . $ failure_message_for(12dea272953de187).(constraint, "actual_value", (intptr_tcxx . . $ intptr_t#)0xabcd12345678);
59
60 assert_thatcxx . . $ intptr_t#(failure_message, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("0xabcd12345678"));
61
62 constraint->destroycxx . . $ Constraint_#destroy.(constraint);
63 freecxx . . $ free(5d22bdacc48458e8).(failure_message);
64 }
65 #endif
66
67 TestSuitecxx . . $ TestSuite# *message_formatting_testscxx . . $ message_formatting_tests(564401a81ded3a53).(void) {
68 TestSuitecxx . . $ TestSuite# *suite = create_test_suitecxx . . $ `include/cgreen/suite.h:20:9`!();
69 add_test_with_contextcxx . . $ `include/cgreen/suite.h:23:9`!(suite, MessageFormatting, can_show_failure_message_containing_percent_sign);
70 #if INTPTR_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:182:11`! > INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!
71 add_test_with_contextcxx . . $ `include/cgreen/suite.h:23:9`!(suite, MessageFormatting, shows_full_width_hex_actual_value_without_truncation);
72 #endif
73 return suite;
74 }