Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ dependencies = [
dependency('gtk+-3.0'),
dependency('granite', version: '>=0.5'),
dependency('libhandy-1', version: '>=0.83.0'),
meson.get_compiler('c').find_library('m', required : false)
meson.get_compiler('c').find_library('m', required : false),
meson.get_compiler('vala').find_library('glib-2.0-fixes', dirs: meson.current_source_dir() / 'vapi')
]

subdir('src')
Expand Down
6 changes: 5 additions & 1 deletion tests/Tests.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ namespace Tests {
int main(string[] args) {
Test.init (ref args);

Test.add_func("/Tests/Util/test_truncating_reminder", Tests.Util.test_truncating_remainder);
// Using GLib.TestSuite allows for set_up/tear_down methods:
Test.get_root ().add(new Util.TruncatingRemainder ());

// If we don't need the set_up/tear_down methods, we can simply register a function:
Test.add_func("/Util/truncating_remaindssser", Util.test_truncating_remainder);

return Test.run();
}
Expand Down
37 changes: 35 additions & 2 deletions tests/Util.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,41 @@

namespace Tests.Util {

class TruncatingRemainder : TestCase {

// test env variables need to be static:
private static string test_value = null;

public TruncatingRemainder () {
base (
"TruncatingRemainder",
set_up, // or: null
test,
tear_down // or: null
);
}

void set_up () {
test_value = "my-test-value";
}

void test () {
assert_true (1.0 == Timer.Util.truncating_remainder (5.0, 4.0));
assert_true (0.0 == Timer.Util.truncating_remainder (7.0, 7.0));

assert_nonnull (test_value);
assert_true ("my-test-value" == test_value);
// https://docs.gtk.org/glib/func.assert_cmpstr.html
// assert_cmpstr (test_value, ==, "my-test-value");
}

void tear_down () {
test_value = null;
}
}

void test_truncating_remainder () {
assert (1.0 == Timer.Util.truncating_remainder (5.0, 4.0));
assert (0.0 == Timer.Util.truncating_remainder (7.0, 7.0));
assert_true (1.0 == Timer.Util.truncating_remainder (5.0, 4.0));
assert_true (0.0 == Timer.Util.truncating_remainder (7.0, 7.0));
}
}
6 changes: 6 additions & 0 deletions vapi/glib-2.0-fixes.vapi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace GLib {
namespace Test {
[CCode (cheader_filename = "glib-2.0/glib/gtestutils.h", cname = "g_test_get_root")]
public static TestSuite get_root ();
}
}