Skip to content

Commit bd69e8b

Browse files
committed
Merge pull request ome#123 from joshmoore/gtest
Migrate from boost to gtest
2 parents f8107f6 + b6362d2 commit bd69e8b

32 files changed

+29360
-664
lines changed

components/blitz/src/ome/services/blitz/impl/DeleteI.java

+2
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ public DeleteHandleI makeAndLaunchHandle(final Ice.Identity id, final DeleteComm
194194
public DeleteHandleI makeAndLaunchHandle(final Ice.Current current, final Ice.Identity id,
195195
final DeleteCommand...commands) {
196196
DeleteHandleI handle = new DeleteHandleI(loadSpecs(), id, sf, afs, commands, cancelTimeoutMs, current.ctx);
197+
handle.setApplicationContext(ctx);
197198
threadPool.getExecutor().execute(handle);
198199
return handle;
199200
}
@@ -204,6 +205,7 @@ public void makeAndRun(final Ice.Identity id, final DeleteCommand...commands) {
204205

205206
public void makeAndRun(final Ice.Current current, final Ice.Identity id, final DeleteCommand...commands) {
206207
DeleteHandleI handle = new DeleteHandleI(loadSpecs(), id, sf, afs, commands, cancelTimeoutMs, current.ctx);
208+
handle.setApplicationContext(ctx);
207209
handle.run();
208210
}
209211

components/tools/OmeroCpp/SConstruct

+13-73
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,19 @@ blitz = os.path.abspath( os.path.join(os.path.curdir, os.path.pardir, os.path.pa
1010
sys.path.append( blitz )
1111
from blitz_tools import *
1212

13-
BOOST_ALL=[
14-
# 1.39
15-
"boost_unit_test_framework-mt-d",
16-
"boost_unit_test_framework-mt",
17-
"boost_unit_test_framework-xgcc40-mt",
18-
"boost_unit_test_framework-vc90-mt-gd-1_39",
19-
# 1.40
20-
"boost_unit_test_framework"
21-
]
22-
2313
#
2414
# At the moment, execution of this script requires,
2515
# ant tools-init to have been run
2616
#
2717

2818
env = OmeroEnvironment(CPPPATH=["src","target"])
2919

30-
boost_check = """
31-
//
32-
// boost_check function from OmeroCpp/SConstruct
33-
// Checks for the existnce of the unit_test.hpp
34-
// header in the current INCLUDE paths. If found,
35-
// A search will be made for the following
36-
// dynamic libs:
37-
//
38-
// %s
39-
//
40-
// INCLUDE paths: %s
41-
// LIBRARY paths: %s
42-
//
43-
#define BOOST_TEST_MAIN
44-
#define BOOST_TEST_DYN_LINK
45-
#include <boost/test/included/unit_test.hpp>
46-
""" % (BOOST_ALL, env["CPPPATH"], env["LIBPATH"])
47-
48-
def CheckBoost(context):
49-
context.Message('Checking for boost_unit_test...')
50-
result = context.TryLink(boost_check, '.cpp')
51-
context.Result(result)
52-
return result
53-
54-
boost_libs = []
55-
5620
if not env.GetOption('clean'):
57-
conf = Configure(env, custom_tests = {'CheckBoost':CheckBoost})
21+
conf = Configure(env)
5822
if not conf.CheckCXXHeader(os.path.join("Ice","Ice.h")):
5923
print 'Ice/Ice.h not found'
6024
env.Exit(1)
61-
has_boost = conf.CheckBoost()
62-
if has_boost:
63-
found = False
64-
for b in BOOST_ALL:
65-
if conf.CheckLib(b):
66-
print "Using %s" % b
67-
boost_libs.append(b)
68-
found = True
69-
break
70-
if not found:
71-
print "*"*50
72-
print " boost_unit_test header found but no library!"
73-
print " checked: %s" % BOOST_ALL
74-
print "*"*50
75-
env.Exit(1)
7625
conf.Finish()
77-
else:
78-
has_boost = True
7926

8027
f = open("scons.log", "w")
8128
f.write(env.Dump())
@@ -171,25 +118,18 @@ else:
171118
#
172119
# Build tests
173120
#
174-
if not has_boost:
175-
if "test" in COMMAND_LINE_TARGETS:
176-
print "*" * 55
177-
print " WARNING: boost_unit_test_framework not installed"
178-
print "*" * 55
179-
# env.Exit(1)
180-
else:
181-
tenv = env.Clone()
182-
tenv["CPPPATH"].append("test")
183-
tenv["ENV"]["BOOST_TEST_DYN_LINK"] = "1"
121+
tenv = env.Clone()
122+
tenv["CPPPATH"].append("test")
184123

185-
main = tenv.Object("test/boost_main.cpp")
186-
fixture = tenv.Object("test/boost_fixture.cpp")
124+
gtest = tenv.Object("test/gtest/gtest-all.cc")
125+
main = tenv.Object("test/gtest/gtest_main.cc")
126+
fixture = tenv.Object("test/omero/fixture.cpp")
187127

188-
def define_test(dir):
189-
test = tenv.Program("test/%s.exe" % dir,
190-
[main, fixture] + tenv.Glob("test/%s/*.cpp" % dir),
191-
LIBS = ["omero_client"]+env.icelibs()+boost_libs)
192-
return test
128+
def define_test(dir):
129+
test = tenv.Program("test/%s.exe" % dir,
130+
[gtest, main, fixture] + tenv.Glob("test/%s/*.cpp" % dir),
131+
LIBS = ["omero_client"]+env.icelibs())
132+
return test
193133

194-
unit = define_test("unit")
195-
integration = define_test("integration")
134+
unit = define_test("unit")
135+
integration = define_test("integration")

components/tools/OmeroCpp/build.xml

+37-16
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,47 @@
3939
<available file="test/integration.exe" property="integration.exe-exists"/>
4040
</target>
4141

42+
<macrodef name="gtest_run">
43+
<attribute name="file" default="test.exe"/>
44+
<element name="args" implicit="yes"/>
45+
<sequential>
46+
<mkdir dir="${basedir}/target/reports"/>
47+
<exec dir="${basedir}" executable="${basedir}/test/@{file}" failonerror="${test.with.fail}">
48+
<env key="ICE_HOME" value="${ice.home}"/>
49+
<env key="LD_LIBRARY_PATH" value="${env.LD_LIBRARY_PATH}:${basedir}"/>
50+
<env key="DYLD_LIBRARY_PATH" value="${env.DYLD_LIBRARY_PATH}:${basedir}"/>
51+
<arg line="--gtest_output=xml:${testreports.dir}/test_results.xml"/>
52+
<args/>
53+
</exec>
54+
</sequential>
55+
</macrodef>
56+
4257
<target name="test" depends="test-compile" if="unit.exe-exists" unless="env.NOMAKE">
43-
<!-- http://forums.sun.com/thread.jspa?threadID=416069 -->
44-
<exec dir="${basedir}" executable="${basedir}/test/unit.exe" failonerror="${test.with.fail}">
45-
<env key="ICE_HOME" value="${ice.home}"/>
46-
<env key="LD_LIBRARY_PATH" value="${env.LD_LIBRARY_PATH}:${basedir}"/>
47-
<env key="DYLD_LIBRARY_PATH" value="${env.DYLD_LIBRARY_PATH}:${basedir}"/>
48-
</exec>
58+
<if>
59+
<isset property="TEST"/>
60+
<then>
61+
<gtest_run file="unit.exe">
62+
<arg value="--gtest_filter=${TEST}"/>
63+
</gtest_run>
64+
</then>
65+
<else>
66+
<gtest_run file="unit.exe"/>
67+
</else>
68+
</if>
4969
</target>
5070

5171
<target name="integration" depends="test-compile" if="integration.exe-exists" unless="env.NOMAKE">
52-
<!-- http://forums.sun.com/thread.jspa?threadID=416069 -->
53-
<mkdir dir="${basedir}/target/reports"/>
54-
<exec dir="${basedir}" executable="${basedir}/test/integration.exe" failonerror="${test.with.fail}"
55-
output="${basedir}/target/reports/boost-integration.xml"
56-
error="${basedir}/target/reports/boost-integration.err">
57-
<env key="ICE_HOME" value="${ice.home}"/>
58-
<env key="LD_LIBRARY_PATH" value="${env.LD_LIBRARY_PATH}:${basedir}"/>
59-
<env key="DYLD_LIBRARY_PATH" value="${env.DYLD_LIBRARY_PATH}:${basedir}"/>
60-
<arg line="--output_format=XML --log_level=message --report_level=detailed"/><!-- for hudson xunit -->
61-
</exec>
72+
<if>
73+
<isset property="TEST"/>
74+
<then>
75+
<gtest_run file="integration.exe">
76+
<arg value="--gtest_filter=${TEST}"/>
77+
</gtest_run>
78+
</then>
79+
<else>
80+
<gtest_run file="integration.exe"/>
81+
</else>
82+
</if>
6283
</target>
6384

6485
<target name="tools-build" depends="tools-init,build" description="Use scons to build the libraries" unless="env.NOMAKE"/>

components/tools/OmeroCpp/src/omero/model/PermissionsI.cpp

+37-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,49 @@
77
*/
88

99
#include <omero/model/PermissionsI.h>
10+
#include <omero/ClientErrors.h>
1011

1112
namespace omero {
1213

1314
namespace model {
1415

1516
PermissionsI::~PermissionsI() {}
16-
PermissionsI::PermissionsI() : Permissions() {
17-
perm1 = -1L;
17+
PermissionsI::PermissionsI(const std::string& perms) : Permissions() {
18+
if (perms.empty()) {
19+
perm1 = -1L;
20+
} else {
21+
// Due to lack of regex libraries
22+
// this implementation is more naive
23+
// than in the other SDKs
24+
std::string rest = perms;
25+
if (rest.size() == 7) {
26+
// ignore the locked character
27+
rest = rest.substr(1);
28+
}
29+
if (rest.size() != 6) {
30+
std::string msg = "Bad permissions:";
31+
msg += perms;
32+
throw omero::ClientError(__FILE__, __LINE__, msg.c_str());
33+
}
34+
if (rest[0] == 'r' || rest[0] == 'R') {
35+
setUserRead(true);
36+
}
37+
if (rest[1] == 'w' || rest[1] == 'W') {
38+
setUserWrite(true);
39+
}
40+
if (rest[2] == 'r' || rest[2] == 'R') {
41+
setGroupRead(true);
42+
}
43+
if (rest[3] == 'w' || rest[3] == 'W') {
44+
setGroupWrite(true);
45+
}
46+
if (rest[4] == 'r' || rest[4] == 'R') {
47+
setWorldRead(true);
48+
}
49+
if (rest[5] == 'w' || rest[5] == 'W') {
50+
setWorldWrite(true);
51+
}
52+
}
1853
}
1954

2055
// shift 8; mask 4

components/tools/OmeroCpp/src/omero/model/PermissionsI.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class OMERO_API PermissionsI : virtual public Permissions {
4444
void set(int mask, int shift, bool value);
4545
public:
4646

47-
PermissionsI();
47+
PermissionsI(const std::string& perms = "");
4848

4949
/*
5050
* Central methods. The optional argument is a requirement
+18-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
To add a test, add the cpp file to the test_SOURCES section of Makefile.am.
2-
"make" will run "make test" and execute the generated "test" binary.
1+
To add a test, add a cpp file under either the test/unit
2+
or test/integration directory. Do not add a main method
3+
but rather use the TEST() macro -- available from either
4+
the gtest.h header or the omero/fixture.h -- to create
5+
a test:
36

4-
Several parameters are available for when running boost tests. E.g.
7+
TEST(TestName, methodName) {
8+
ASSERT_EQ(1, 1);
9+
ASSERT_NE(1, 2);
10+
ASSERT_GT(2, 1);
11+
ASSERT_LE(1, 1);
12+
FAIL() << "This will never succeed.";
13+
}
514

6-
./integration --report_level=detailed --catch_system_errors=no --detect_memory_leak=0 --build_info=yes
15+
These can be run either manually:
716

8-
See http://beta.boost.org/doc/libs/1_34_1/libs/test/doc/components/utf/parameters/index.html for more.
17+
DYLD_LIBRARY_PATH=. test/integration.exe
18+
DYLD_LIBRARY_PATH=. test/unit.exe --gtest_filter=Model*
919

10-
* build_info
11-
* catch_system_errors
12-
* detect_memory_leaks
13-
* log_format
14-
* log_level
15-
* no_result_code
16-
* output_format
17-
* random
18-
* report_format
19-
* report_level = "no", "confirm", "short", "detailed"
20-
* show_progress
20+
or via the build:
2121

22+
./build.py -f components/tools/OmeroCpp/build.xml integration
23+
./build.py -f components/tools/OmeroCpp/build.xml test -DTEST=Model*

components/tools/OmeroCpp/test/boost_fixture.h

-75
This file was deleted.

components/tools/OmeroCpp/test/boost_main.cpp

-14
This file was deleted.

0 commit comments

Comments
 (0)