comparison tests/js-irccd/main.cpp @ 75:f8160d515a76

Irccd: rework a lot the JavaScript library
author David Demelier <markand@malikania.fr>
date Wed, 30 Mar 2016 13:52:47 +0200
parents 1158cffe5a5e
children 98bd4d6355fe
comparison
equal deleted inserted replaced
74:35ef15100de8 75:f8160d515a76
18 18
19 #include <gtest/gtest.h> 19 #include <gtest/gtest.h>
20 20
21 #include <irccd-config.h> 21 #include <irccd-config.h>
22 22
23 #include <logger.h> 23 #include <irccd/js-irccd.h>
24 24 #include <irccd/logger.h>
25 #include <js-irccd.h>
26 25
27 using namespace irccd; 26 using namespace irccd;
28 27
29 TEST(TestJsIrccd, version) 28 TEST(TestJsIrccd, version)
30 { 29 {
31 js::Context ctx; 30 duk::Context ctx;
32 31
33 loadJsIrccd(ctx); 32 loadJsIrccd(ctx);
34 33
35 try { 34 try {
36 ctx.peval(js::Script{ 35 auto ret = duk::pevalString(ctx,
37 "major = Irccd.version.major;" 36 "major = Irccd.version.major;"
38 "minor = Irccd.version.minor;" 37 "minor = Irccd.version.minor;"
39 "patch = Irccd.version.patch;" 38 "patch = Irccd.version.patch;"
40 }); 39 );
41 40
42 ASSERT_EQ(IRCCD_VERSION_MAJOR, ctx.getGlobal<int>("major")); 41 if (ret != 0)
43 ASSERT_EQ(IRCCD_VERSION_MINOR, ctx.getGlobal<int>("minor")); 42 throw duk::error(ctx, -1);
44 ASSERT_EQ(IRCCD_VERSION_PATCH, ctx.getGlobal<int>("patch")); 43
44 ASSERT_EQ(IRCCD_VERSION_MAJOR, duk::getGlobal<int>(ctx, "major"));
45 ASSERT_EQ(IRCCD_VERSION_MINOR, duk::getGlobal<int>(ctx, "minor"));
46 ASSERT_EQ(IRCCD_VERSION_PATCH, duk::getGlobal<int>(ctx, "patch"));
45 } catch (const std::exception &ex) { 47 } catch (const std::exception &ex) {
46 FAIL() << ex.what(); 48 FAIL() << ex.what();
47 } 49 }
48 } 50 }
49 51