コード例 #1
0
void ClassTestSuite::testMethodSearch()
{
	Class test = Class::lookup("ClassTest::Test1");

	auto retDouble = test.findAllMethods([&](const Method& m) {
		return m.returnSpelling() == "double";
	});

	TS_ASSERT_EQUALS(retDouble.size(), 3);

	auto retDoubleStrict = test.findAllMethods([&](const Method& m) {
		return m.returnSpelling() == "double" && m.getClass() == test; //filter out inherited methods
	});

	TS_ASSERT_EQUALS(retDoubleStrict.size(), 2);

	auto constMethods = test.findAllMethods([&](const Method& m) {
		return m.isConst();
	});

	TS_ASSERT_EQUALS(constMethods.size(), 2);

	Method m = test.findMethod([&](const Method& m) {
			   return m.name() == "method1";
		   });

	TS_ASSERT(m.isValid());
	TS_ASSERT(m.isConst());
	TS_ASSERT_EQUALS(m.returnSpelling(), "std::string");


	Method m30 = test.findMethod([&](const Method& m) {
			   return m.name() == "method30";
		   });

	TS_ASSERT(!m30.isValid());
	TS_ASSERT_THROWS_ANYTHING(m30.isConst());
}