Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 99440b6

Browse files
[[ cpptest ]] Add test framework to libfoundation
1 parent 72d91ce commit 99440b6

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

libfoundation/libfoundation.gyp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
{
2+
'variables':
3+
{
4+
'module_name': 'libFoundation',
5+
'module_test_dependencies':
6+
[
7+
'libFoundation',
8+
],
9+
},
10+
11+
212
'includes':
313
[
414
'../common.gypi',
15+
'../config/cpptest.gypi'
516
],
617

718
'targets':

libfoundation/test/environment.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* Copyright (C) 2003-2015 LiveCode Ltd.
2+
3+
This file is part of LiveCode.
4+
5+
LiveCode is free software; you can redistribute it and/or modify it under
6+
the terms of the GNU General Public License v3 as published by the Free
7+
Software Foundation.
8+
9+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
10+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
16+
17+
#include "gtest/gtest.h"
18+
19+
#include "foundation.h"
20+
21+
//
22+
// The libfoundation testing environment
23+
//
24+
class LibfoundationEnvironment : public ::testing::Environment {
25+
public:
26+
virtual ~LibfoundationEnvironment() {}
27+
28+
virtual void SetUp() {
29+
ASSERT_TRUE(MCInitialize());
30+
}
31+
32+
virtual void TearDown() {
33+
MCFinalize();
34+
}
35+
};
36+
37+
// Register the environment
38+
::testing::Environment* const libfoundation_env =
39+
::testing::AddGlobalTestEnvironment(new LibfoundationEnvironment);

libfoundation/test/test_string.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* Copyright (C) 2003-2015 LiveCode Ltd.
2+
3+
This file is part of LiveCode.
4+
5+
LiveCode is free software; you can redistribute it and/or modify it under
6+
the terms of the GNU General Public License v3 as published by the Free
7+
Software Foundation.
8+
9+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
10+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
16+
17+
#include "gtest/gtest.h"
18+
19+
#include "foundation.h"
20+
#include "foundation-auto.h"
21+
22+
23+
TEST(string, creation)
24+
//
25+
// Checks string creation.
26+
//
27+
{
28+
MCAutoStringRef t_string;
29+
30+
const char* t_c_string = "Hello";
31+
ASSERT_TRUE(
32+
MCStringCreateWithBytes(
33+
reinterpret_cast<const byte_t*>(t_c_string),
34+
5,
35+
kMCStringEncodingASCII,
36+
false,
37+
&t_string
38+
)
39+
);
40+
41+
ASSERT_STREQ(t_c_string, MCStringGetCString(*t_string));
42+
}
43+

livecode.gyp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
'dependencies':
194194
[
195195
'libcpptest/libcpptest.gyp:test-libcpptest<(javascriptify)',
196+
'libfoundation/libfoundation.gyp:test-libFoundation<(javascriptify)',
196197
'engine/kernel-standalone.gyp:test-kernel-standalone<(javascriptify)',
197198
],
198199

@@ -228,6 +229,7 @@
228229
'dependencies':
229230
[
230231
'libcpptest/libcpptest.gyp:run-test-libcpptest',
232+
'libfoundation/libfoundation.gyp:run-test-libFoundation',
231233
'engine/kernel-standalone.gyp:run-test-kernel-standalone',
232234
],
233235

0 commit comments

Comments
 (0)