MCPcopy Create free account
hub / github.com/GothenburgBitFactory/taskwarrior / TEST_NAME

Function TEST_NAME

test/variant_cast_test.cpp:38–257  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

36
37////////////////////////////////////////////////////////////////////////////////
38int TEST_NAME(int, char**) {
39 UnitTest t(81);
40
41 time_t now = time(nullptr);
42
43 try {
44 // Variant::type_boolean --> *
45 Variant v00(true);
46 v00.cast(Variant::type_boolean);
47 t.ok(v00.type() == Variant::type_boolean, "cast boolean --> boolean");
48 t.ok(v00.get_bool() == true, "cast boolean --> boolean");
49
50 Variant v01(true);
51 v01.cast(Variant::type_integer);
52 t.ok(v01.type() == Variant::type_integer, "cast boolean --> integer");
53 t.ok(v01.get_integer() == 1, "cast boolean --> integer");
54
55 Variant v02(true);
56 v02.cast(Variant::type_real);
57 t.ok(v02.type() == Variant::type_real, "cast boolean --> real");
58 t.is(v02.get_real(), 1.0, EPSILON, "cast boolean --> real");
59
60 Variant v03(true);
61 v03.cast(Variant::type_string);
62 t.ok(v03.type() == Variant::type_string, "cast boolean --> string");
63 t.ok(v03.get_string() == "true", "cast boolean --> string");
64
65 Variant v04(true);
66 v04.cast(Variant::type_date);
67 t.ok(v04.type() == Variant::type_date, "cast boolean --> date");
68 t.is(v04.get_date(), 1, "cast boolean --> date");
69
70 Variant v05(true);
71 v05.cast(Variant::type_duration);
72 t.ok(v05.type() == Variant::type_duration, "cast boolean --> duration");
73 t.is(v05.get_duration(), 1, "cast boolean --> duration");
74
75 // Variant::type_integer --> *
76 Variant v10(42);
77 v10.cast(Variant::type_boolean);
78 t.ok(v10.type() == Variant::type_boolean, "cast integer --> boolean");
79 t.ok(v10.get_bool() == true, "cast integer --> boolean");
80
81 Variant v11(42);
82 v11.cast(Variant::type_integer);
83 t.ok(v11.type() == Variant::type_integer, "cast integer --> integer");
84 t.ok(v11.get_integer() == 42, "cast integer --> integer");
85
86 Variant v12(42);
87 v12.cast(Variant::type_real);
88 t.ok(v12.type() == Variant::type_real, "cast integer --> real");
89 t.is(v12.get_real(), 42.0, EPSILON, "cast integer --> real");
90
91 Variant v13(42);
92 v13.cast(Variant::type_string);
93 t.is(v13.type(), Variant::type_string, "cast integer --> string");
94 t.is(v13.get_string(), "42", "cast integer --> string");
95

Callers

nothing calls this directly

Calls 10

castMethod · 0.80
okMethod · 0.80
typeMethod · 0.80
get_boolMethod · 0.80
get_integerMethod · 0.80
isMethod · 0.80
get_realMethod · 0.80
get_durationMethod · 0.80
get_dateMethod · 0.45
diagMethod · 0.45

Tested by

no test coverage detected