Add Method tests
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/31c42325 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/31c42325 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/31c42325 Branch: refs/heads/master Commit: 31c42325625decf11024f5911462d5e5482393c4 Parents: 5f7272e Author: Nick Wellnhofer <[email protected]> Authored: Sat May 14 18:38:29 2016 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Sun May 15 17:57:34 2016 +0200 ---------------------------------------------------------------------- runtime/core/Clownfish/Test.c | 2 + runtime/core/Clownfish/Test/TestMethod.c | 91 +++++++++++++++++++++++++ runtime/core/Clownfish/Test/TestMethod.cfh | 28 ++++++++ runtime/perl/t/core/011-method.t | 23 +++++++ 4 files changed, 144 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/31c42325/runtime/core/Clownfish/Test.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test.c b/runtime/core/Clownfish/Test.c index e5a9f50..4ae6163 100644 --- a/runtime/core/Clownfish/Test.c +++ b/runtime/core/Clownfish/Test.c @@ -32,6 +32,7 @@ #include "Clownfish/Test/TestHash.h" #include "Clownfish/Test/TestHashIterator.h" #include "Clownfish/Test/TestLockFreeRegistry.h" +#include "Clownfish/Test/TestMethod.h" #include "Clownfish/Test/TestNum.h" #include "Clownfish/Test/TestObj.h" #include "Clownfish/Test/TestPtrHash.h" @@ -45,6 +46,7 @@ Test_create_test_suite() { TestSuite *suite = TestSuite_new(); TestSuite_Add_Batch(suite, (TestBatch*)TestClass_new()); + TestSuite_Add_Batch(suite, (TestBatch*)TestMethod_new()); TestSuite_Add_Batch(suite, (TestBatch*)TestVector_new()); TestSuite_Add_Batch(suite, (TestBatch*)TestHash_new()); TestSuite_Add_Batch(suite, (TestBatch*)TestHashIterator_new()); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/31c42325/runtime/core/Clownfish/Test/TestMethod.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestMethod.c b/runtime/core/Clownfish/Test/TestMethod.c new file mode 100644 index 0000000..7c39759 --- /dev/null +++ b/runtime/core/Clownfish/Test/TestMethod.c @@ -0,0 +1,91 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define CFISH_USE_SHORT_NAMES +#define TESTCFISH_USE_SHORT_NAMES + +#include "Clownfish/Test/TestMethod.h" + +#include "Clownfish/Err.h" +#include "Clownfish/Method.h" +#include "Clownfish/String.h" +#include "Clownfish/TestHarness/TestBatchRunner.h" + +TestMethod* +TestMethod_new() { + return (TestMethod*)Class_Make_Obj(TESTMETHOD); +} + +static void +S_set_host_alias(void *context) { + Method *method = (Method*)context; + Method_Set_Host_Alias(method, SSTR_WRAP_C("foo")); +} + +static void +test_accessors(TestBatchRunner *runner) { + String *name = SSTR_WRAP_C("Frobnicate_Widget"); + Method *method = Method_new(name, NULL, 0); + + TEST_TRUE(runner, Str_Equals(Method_Get_Name(method), (Obj*)name), + "Get_Name"); + + String *alias = SSTR_WRAP_C("host_frob"); + Method_Set_Host_Alias(method, alias); + TEST_TRUE(runner, Str_Equals(Method_Get_Host_Alias(method), (Obj*)alias), + "Set_Host_Alias"); + Err *error = Err_trap(S_set_host_alias, method); + TEST_TRUE(runner, error != NULL, + "Set_Host_Alias can't be called more than once"); + DECREF(error); + + TEST_FALSE(runner, Method_Is_Excluded_From_Host(method), + "Is_Excluded_From_Host"); + + Method_Destroy(method); +} + +static void +test_lower_snake_alias(TestBatchRunner *runner) { + String *name = SSTR_WRAP_C("Frobnicate_Widget"); + Method *method = Method_new(name, NULL, 0); + + { + String *alias = Method_lower_snake_alias(method); + TEST_TRUE(runner, Str_Equals_Utf8(alias, "frobnicate_widget", 17), + "lower_snake_alias without explicit alias"); + DECREF(alias); + } + + { + String *new_alias = SSTR_WRAP_C("host_frob"); + Method_Set_Host_Alias(method, new_alias); + String *alias = Method_lower_snake_alias(method); + TEST_TRUE(runner, Str_Equals(alias, (Obj*)new_alias), + "lower_snake_alias with explicit alias"); + DECREF(alias); + } + + Method_Destroy(method); +} + +void +TestMethod_Run_IMP(TestMethod *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 6); + test_accessors(runner); + test_lower_snake_alias(runner); +} + http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/31c42325/runtime/core/Clownfish/Test/TestMethod.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestMethod.cfh b/runtime/core/Clownfish/Test/TestMethod.cfh new file mode 100644 index 0000000..76b9558 --- /dev/null +++ b/runtime/core/Clownfish/Test/TestMethod.cfh @@ -0,0 +1,28 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +parcel TestClownfish; + +class Clownfish::Test::TestMethod + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestMethod* + new(); + + void + Run(TestMethod *self, TestBatchRunner *runner); +} + http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/31c42325/runtime/perl/t/core/011-method.t ---------------------------------------------------------------------- diff --git a/runtime/perl/t/core/011-method.t b/runtime/perl/t/core/011-method.t new file mode 100644 index 0000000..92f709a --- /dev/null +++ b/runtime/perl/t/core/011-method.t @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use strict; +use warnings; + +use Clownfish::Test; +my $success = Clownfish::Test::run_tests("Clownfish::Test::TestMethod"); + +exit($success ? 0 : 1); +
