Move tests to separate directory
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/8ba4e619 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/8ba4e619 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/8ba4e619 Branch: refs/heads/master Commit: 8ba4e61987f00db2624818c4fa1a6f9c1b4f79b8 Parents: 5bda4da Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Fri Jul 8 13:57:13 2016 +0200 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Fri Jul 8 14:25:36 2016 +0200 ---------------------------------------------------------------------- runtime/common/charmonizer.c | 7 + runtime/common/charmonizer.main | 7 + runtime/core/Clownfish/Test.c | 70 -- runtime/core/Clownfish/Test.cfh | 26 - runtime/core/Clownfish/Test/TestBlob.c | 147 ---- runtime/core/Clownfish/Test/TestBlob.cfh | 28 - runtime/core/Clownfish/Test/TestBoolean.c | 99 --- runtime/core/Clownfish/Test/TestBoolean.cfh | 29 - runtime/core/Clownfish/Test/TestByteBuf.c | 218 ----- runtime/core/Clownfish/Test/TestByteBuf.cfh | 29 - runtime/core/Clownfish/Test/TestCharBuf.c | 394 --------- runtime/core/Clownfish/Test/TestCharBuf.cfh | 29 - runtime/core/Clownfish/Test/TestClass.c | 158 ---- runtime/core/Clownfish/Test/TestClass.cfh | 28 - runtime/core/Clownfish/Test/TestErr.c | 193 ----- runtime/core/Clownfish/Test/TestErr.cfh | 28 - runtime/core/Clownfish/Test/TestHash.c | 325 ------- runtime/core/Clownfish/Test/TestHash.cfh | 29 - runtime/core/Clownfish/Test/TestHashIterator.c | 253 ------ .../core/Clownfish/Test/TestHashIterator.cfh | 29 - runtime/core/Clownfish/Test/TestHost.c | 125 --- runtime/core/Clownfish/Test/TestHost.cfh | 81 -- .../core/Clownfish/Test/TestLockFreeRegistry.c | 168 ---- .../Clownfish/Test/TestLockFreeRegistry.cfh | 29 - runtime/core/Clownfish/Test/TestMethod.c | 91 -- runtime/core/Clownfish/Test/TestMethod.cfh | 28 - runtime/core/Clownfish/Test/TestNum.c | 278 ------ runtime/core/Clownfish/Test/TestNum.cfh | 29 - runtime/core/Clownfish/Test/TestObj.c | 152 ---- runtime/core/Clownfish/Test/TestObj.cfh | 28 - runtime/core/Clownfish/Test/TestPtrHash.c | 108 --- runtime/core/Clownfish/Test/TestPtrHash.cfh | 29 - runtime/core/Clownfish/Test/TestString.c | 848 ------------------- runtime/core/Clownfish/Test/TestString.cfh | 36 - runtime/core/Clownfish/Test/TestVector.c | 572 ------------- runtime/core/Clownfish/Test/TestVector.cfh | 29 - runtime/core/Clownfish/Test/Util/TestAtomic.c | 65 -- runtime/core/Clownfish/Test/Util/TestAtomic.cfh | 29 - runtime/core/Clownfish/Test/Util/TestMemory.c | 119 --- runtime/core/Clownfish/Test/Util/TestMemory.cfh | 29 - .../core/Clownfish/Test/Util/TestStringHelper.c | 373 -------- .../Clownfish/Test/Util/TestStringHelper.cfh | 29 - runtime/core/TestClownfish.c | 22 - runtime/core/TestClownfish.cfp | 8 - runtime/go/build.go | 1 + runtime/perl/buildlib/Clownfish/Build.pm | 6 +- runtime/python/setup.py | 2 + runtime/test/Clownfish/Test.c | 70 ++ runtime/test/Clownfish/Test.cfh | 26 + runtime/test/Clownfish/Test/TestBlob.c | 147 ++++ runtime/test/Clownfish/Test/TestBlob.cfh | 28 + runtime/test/Clownfish/Test/TestBoolean.c | 99 +++ runtime/test/Clownfish/Test/TestBoolean.cfh | 29 + runtime/test/Clownfish/Test/TestByteBuf.c | 218 +++++ runtime/test/Clownfish/Test/TestByteBuf.cfh | 29 + runtime/test/Clownfish/Test/TestCharBuf.c | 394 +++++++++ runtime/test/Clownfish/Test/TestCharBuf.cfh | 29 + runtime/test/Clownfish/Test/TestClass.c | 158 ++++ runtime/test/Clownfish/Test/TestClass.cfh | 28 + runtime/test/Clownfish/Test/TestErr.c | 193 +++++ runtime/test/Clownfish/Test/TestErr.cfh | 28 + runtime/test/Clownfish/Test/TestHash.c | 325 +++++++ runtime/test/Clownfish/Test/TestHash.cfh | 29 + runtime/test/Clownfish/Test/TestHashIterator.c | 253 ++++++ .../test/Clownfish/Test/TestHashIterator.cfh | 29 + runtime/test/Clownfish/Test/TestHost.c | 125 +++ runtime/test/Clownfish/Test/TestHost.cfh | 81 ++ .../test/Clownfish/Test/TestLockFreeRegistry.c | 168 ++++ .../Clownfish/Test/TestLockFreeRegistry.cfh | 29 + runtime/test/Clownfish/Test/TestMethod.c | 91 ++ runtime/test/Clownfish/Test/TestMethod.cfh | 28 + runtime/test/Clownfish/Test/TestNum.c | 278 ++++++ runtime/test/Clownfish/Test/TestNum.cfh | 29 + runtime/test/Clownfish/Test/TestObj.c | 152 ++++ runtime/test/Clownfish/Test/TestObj.cfh | 28 + runtime/test/Clownfish/Test/TestPtrHash.c | 108 +++ runtime/test/Clownfish/Test/TestPtrHash.cfh | 29 + runtime/test/Clownfish/Test/TestString.c | 848 +++++++++++++++++++ runtime/test/Clownfish/Test/TestString.cfh | 36 + runtime/test/Clownfish/Test/TestVector.c | 572 +++++++++++++ runtime/test/Clownfish/Test/TestVector.cfh | 29 + runtime/test/Clownfish/Test/Util/TestAtomic.c | 65 ++ runtime/test/Clownfish/Test/Util/TestAtomic.cfh | 29 + runtime/test/Clownfish/Test/Util/TestMemory.c | 119 +++ runtime/test/Clownfish/Test/Util/TestMemory.cfh | 29 + .../test/Clownfish/Test/Util/TestStringHelper.c | 373 ++++++++ .../Clownfish/Test/Util/TestStringHelper.cfh | 29 + runtime/test/TestClownfish.c | 22 + runtime/test/TestClownfish.cfp | 8 + 89 files changed, 5439 insertions(+), 5418 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/common/charmonizer.c ---------------------------------------------------------------------- diff --git a/runtime/common/charmonizer.c b/runtime/common/charmonizer.c index 7448e25..af37cfd 100644 --- a/runtime/common/charmonizer.c +++ b/runtime/common/charmonizer.c @@ -8597,6 +8597,7 @@ typedef struct cfish_MakeFile { const char *base_dir; const char *host_src_dir; char *core_dir; + char *test_dir; char *autogen_src_dir; char *autogen_inc_dir; char *autogen_target; @@ -8807,8 +8808,10 @@ cfish_MakeFile_new(chaz_CLI *cli) { self->cfh_var = NULL; self->cli = cli; + /* TODO: Detect base directory. */ self->base_dir = ".."; self->core_dir = chaz_Util_join(dir_sep, self->base_dir, "core", NULL); + self->test_dir = chaz_Util_join(dir_sep, self->base_dir, "test", NULL); self->autogen_src_dir = chaz_Util_join(dir_sep, "autogen", "source", NULL); self->autogen_inc_dir = chaz_Util_join(dir_sep, "autogen", "include", NULL); @@ -8838,6 +8841,7 @@ cfish_MakeFile_destroy(cfish_MakeFile *self) { chaz_MakeFile_destroy(self->makefile); free(self->core_dir); + free(self->test_dir); free(self->autogen_inc_dir); free(self->autogen_src_dir); free(self->autogen_target); @@ -8924,6 +8928,7 @@ cfish_MakeFile_write(cfish_MakeFile *self, chaz_CFlags *extra_link_flags) { chaz_MakeBinary_add_src_dir(self->binary, self->host_src_dir); } chaz_MakeBinary_add_src_dir(self->binary, self->core_dir); + chaz_MakeBinary_add_src_dir(self->binary, self->test_dir); compile_flags = chaz_MakeBinary_get_compile_flags(self->binary); chaz_CFlags_add_define(compile_flags, "CFP_CFISH", NULL); @@ -8988,10 +8993,12 @@ cfish_MakeFile_write_c_cfc_rules(cfish_MakeFile *self) { self->cfh_var = chaz_MakeFile_add_var(self->makefile, "CLOWNFISH_HEADERS", NULL); chaz_Make_list_files(self->core_dir, "cfh", S_cfh_file_callback, self); + chaz_Make_list_files(self->test_dir, "cfh", S_cfh_file_callback, self); rule = chaz_MakeFile_add_rule(self->makefile, self->autogen_target, cfc_exe); chaz_MakeRule_add_prereq(rule, "$(CLOWNFISH_HEADERS)"); cfc_command = chaz_Util_join("", cfc_exe, " --source=", self->core_dir, + " --source=", self->test_dir, " --dest=autogen --header=cfc_header", NULL); chaz_MakeRule_add_command(rule, cfc_command); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/common/charmonizer.main ---------------------------------------------------------------------- diff --git a/runtime/common/charmonizer.main b/runtime/common/charmonizer.main index e777c52..7ceb2dd 100644 --- a/runtime/common/charmonizer.main +++ b/runtime/common/charmonizer.main @@ -49,6 +49,7 @@ typedef struct cfish_MakeFile { const char *base_dir; const char *host_src_dir; char *core_dir; + char *test_dir; char *autogen_src_dir; char *autogen_inc_dir; char *autogen_target; @@ -259,8 +260,10 @@ cfish_MakeFile_new(chaz_CLI *cli) { self->cfh_var = NULL; self->cli = cli; + /* TODO: Detect base directory. */ self->base_dir = ".."; self->core_dir = chaz_Util_join(dir_sep, self->base_dir, "core", NULL); + self->test_dir = chaz_Util_join(dir_sep, self->base_dir, "test", NULL); self->autogen_src_dir = chaz_Util_join(dir_sep, "autogen", "source", NULL); self->autogen_inc_dir = chaz_Util_join(dir_sep, "autogen", "include", NULL); @@ -290,6 +293,7 @@ cfish_MakeFile_destroy(cfish_MakeFile *self) { chaz_MakeFile_destroy(self->makefile); free(self->core_dir); + free(self->test_dir); free(self->autogen_inc_dir); free(self->autogen_src_dir); free(self->autogen_target); @@ -376,6 +380,7 @@ cfish_MakeFile_write(cfish_MakeFile *self, chaz_CFlags *extra_link_flags) { chaz_MakeBinary_add_src_dir(self->binary, self->host_src_dir); } chaz_MakeBinary_add_src_dir(self->binary, self->core_dir); + chaz_MakeBinary_add_src_dir(self->binary, self->test_dir); compile_flags = chaz_MakeBinary_get_compile_flags(self->binary); chaz_CFlags_add_define(compile_flags, "CFP_CFISH", NULL); @@ -440,10 +445,12 @@ cfish_MakeFile_write_c_cfc_rules(cfish_MakeFile *self) { self->cfh_var = chaz_MakeFile_add_var(self->makefile, "CLOWNFISH_HEADERS", NULL); chaz_Make_list_files(self->core_dir, "cfh", S_cfh_file_callback, self); + chaz_Make_list_files(self->test_dir, "cfh", S_cfh_file_callback, self); rule = chaz_MakeFile_add_rule(self->makefile, self->autogen_target, cfc_exe); chaz_MakeRule_add_prereq(rule, "$(CLOWNFISH_HEADERS)"); cfc_command = chaz_Util_join("", cfc_exe, " --source=", self->core_dir, + " --source=", self->test_dir, " --dest=autogen --header=cfc_header", NULL); chaz_MakeRule_add_command(rule, cfc_command); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test.c b/runtime/core/Clownfish/Test.c deleted file mode 100644 index 4ae6163..0000000 --- a/runtime/core/Clownfish/Test.c +++ /dev/null @@ -1,70 +0,0 @@ -/* 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.h" - -#include "Clownfish/TestHarness/TestBatch.h" -#include "Clownfish/TestHarness/TestSuite.h" - -#include "Clownfish/Test/TestBlob.h" -#include "Clownfish/Test/TestBoolean.h" -#include "Clownfish/Test/TestByteBuf.h" -#include "Clownfish/Test/TestString.h" -#include "Clownfish/Test/TestCharBuf.h" -#include "Clownfish/Test/TestClass.h" -#include "Clownfish/Test/TestErr.h" -#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" -#include "Clownfish/Test/TestVector.h" -#include "Clownfish/Test/Util/TestAtomic.h" -#include "Clownfish/Test/Util/TestMemory.h" -#include "Clownfish/Test/Util/TestStringHelper.h" - -TestSuite* -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()); - TestSuite_Add_Batch(suite, (TestBatch*)TestObj_new()); - TestSuite_Add_Batch(suite, (TestBatch*)TestErr_new()); - TestSuite_Add_Batch(suite, (TestBatch*)TestBlob_new()); - TestSuite_Add_Batch(suite, (TestBatch*)TestBB_new()); - TestSuite_Add_Batch(suite, (TestBatch*)TestStr_new()); - TestSuite_Add_Batch(suite, (TestBatch*)TestCB_new()); - TestSuite_Add_Batch(suite, (TestBatch*)TestBoolean_new()); - TestSuite_Add_Batch(suite, (TestBatch*)TestNum_new()); - TestSuite_Add_Batch(suite, (TestBatch*)TestStrHelp_new()); - TestSuite_Add_Batch(suite, (TestBatch*)TestAtomic_new()); - TestSuite_Add_Batch(suite, (TestBatch*)TestLFReg_new()); - TestSuite_Add_Batch(suite, (TestBatch*)TestMemory_new()); - TestSuite_Add_Batch(suite, (TestBatch*)TestPtrHash_new()); - - return suite; -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test.cfh b/runtime/core/Clownfish/Test.cfh deleted file mode 100644 index 68dc8bc..0000000 --- a/runtime/core/Clownfish/Test.cfh +++ /dev/null @@ -1,26 +0,0 @@ -/* 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; - -/** Clownfish test suite. - */ -inert class Clownfish::Test { - inert incremented TestSuite* - create_test_suite(); -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestBlob.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestBlob.c b/runtime/core/Clownfish/Test/TestBlob.c deleted file mode 100644 index 5776f47..0000000 --- a/runtime/core/Clownfish/Test/TestBlob.c +++ /dev/null @@ -1,147 +0,0 @@ -/* 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/TestBlob.h" - -#include "Clownfish/Blob.h" -#include "Clownfish/Test.h" -#include "Clownfish/TestHarness/TestBatchRunner.h" -#include "Clownfish/TestHarness/TestUtils.h" -#include "Clownfish/Class.h" -#include "Clownfish/Util/Memory.h" - -#include <string.h> - -TestBlob* -TestBlob_new() { - return (TestBlob*)Class_Make_Obj(TESTBLOB); -} - -static void -test_new_steal(TestBatchRunner *runner) { - size_t size = 4; - char *buf = (char*)MALLOCATE(size); - memset(buf, 'x', size); - Blob *blob = Blob_new_steal(buf, size); - TEST_TRUE(runner, Blob_Get_Buf(blob) == buf, "new_steal steals buf"); - TEST_TRUE(runner, Blob_Equals_Bytes(blob, "xxxx", 4), - "new_steal doesn't change buf"); - DECREF(blob); -} - -static void -test_new_wrap(TestBatchRunner *runner) { - static const char buf[] = "xxxx"; - Blob *blob = Blob_new_wrap(buf, 4); - TEST_TRUE(runner, Blob_Get_Buf(blob) == buf, "new_wrap wraps buf"); - TEST_TRUE(runner, Blob_Equals_Bytes(blob, "xxxx", 4), - "new_wrap doesn't change buf"); - DECREF(blob); -} - -static void -test_Equals(TestBatchRunner *runner) { - Blob *blob = Blob_new("foo", 4); // Include terminating NULL. - - { - Blob *other = Blob_new("foo", 4); - TEST_TRUE(runner, Blob_Equals(blob, (Obj*)other), "Equals"); - DECREF(other); - } - - { - Blob *other = Blob_new("foo", 3); - TEST_FALSE(runner, Blob_Equals(blob, (Obj*)other), - "Different size spoils Equals"); - DECREF(other); - } - - { - Blob *other = Blob_new("bar", 4); - TEST_UINT_EQ(runner, Blob_Get_Size(blob), Blob_Get_Size(other), - "same length"); - TEST_FALSE(runner, Blob_Equals(blob, (Obj*)other), - "Different content spoils Equals"); - DECREF(other); - } - - TEST_FALSE(runner, Blob_Equals(blob, (Obj*)BLOB), - "Different type spoils Equals"); - - TEST_TRUE(runner, Blob_Equals_Bytes(blob, "foo", 4), "Equals_Bytes"); - TEST_FALSE(runner, Blob_Equals_Bytes(blob, "foo", 3), - "Equals_Bytes spoiled by different size"); - TEST_FALSE(runner, Blob_Equals_Bytes(blob, "bar", 4), - "Equals_Bytes spoiled by different content"); - - DECREF(blob); -} - -static void -test_Clone(TestBatchRunner *runner) { - Blob *blob = Blob_new("foo", 3); - Blob *twin = Blob_Clone(blob); - TEST_TRUE(runner, Blob_Equals(blob, (Obj*)twin), "Clone"); - DECREF(blob); - DECREF(twin); -} - -static void -test_Compare_To(TestBatchRunner *runner) { - { - Blob *a = Blob_new("foo", 4); - Blob *b = Blob_new("foo", 4); - TEST_INT_EQ(runner, Blob_Compare_To(a, (Obj*)b), 0, - "Compare_To returns 0 for equal Blobs"); - DECREF(a); - DECREF(b); - } - - { - Blob *a = Blob_new("foo", 3); - Blob *b = Blob_new("foo\0b", 5); - TEST_TRUE(runner, Blob_Compare_To(a, (Obj*)b) < 0, - "shorter Blob sorts first"); - TEST_TRUE(runner, Blob_Compare_To(b, (Obj*)a) > 0, - "longer Blob sorts last"); - DECREF(a); - DECREF(b); - } - - { - Blob *a = Blob_new("foo\0a", 5); - Blob *b = Blob_new("foo\0b", 5); - TEST_TRUE(runner, Blob_Compare_To(a, (Obj*)b) < 0, - "NULL doesn't interfere with Compare_To"); - DECREF(a); - DECREF(b); - } -} - -void -TestBlob_Run_IMP(TestBlob *self, TestBatchRunner *runner) { - TestBatchRunner_Plan(runner, (TestBatch*)self, 17); - test_new_steal(runner); - test_new_wrap(runner); - test_Equals(runner); - test_Clone(runner); - test_Compare_To(runner); -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestBlob.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestBlob.cfh b/runtime/core/Clownfish/Test/TestBlob.cfh deleted file mode 100644 index 4d3d4b6..0000000 --- a/runtime/core/Clownfish/Test/TestBlob.cfh +++ /dev/null @@ -1,28 +0,0 @@ -/* 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::TestBlob inherits Clownfish::TestHarness::TestBatch { - - inert incremented TestBlob* - new(); - - void - Run(TestBlob *self, TestBatchRunner *runner); -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestBoolean.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestBoolean.c b/runtime/core/Clownfish/Test/TestBoolean.c deleted file mode 100644 index 8835fe1..0000000 --- a/runtime/core/Clownfish/Test/TestBoolean.c +++ /dev/null @@ -1,99 +0,0 @@ -/* 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/TestBoolean.h" - -#include "Clownfish/String.h" -#include "Clownfish/Boolean.h" -#include "Clownfish/Test.h" -#include "Clownfish/TestHarness/TestBatchRunner.h" -#include "Clownfish/TestHarness/TestUtils.h" -#include "Clownfish/Class.h" - -TestBoolean* -TestBoolean_new() { - return (TestBoolean*)Class_Make_Obj(TESTBOOLEAN); -} - -static void -test_singleton(TestBatchRunner *runner) { - TEST_TRUE(runner, Bool_singleton(true) == CFISH_TRUE, - "Bool_singleton true"); - TEST_TRUE(runner, Bool_singleton(false) == CFISH_FALSE, - "Bool_singleton false"); -} - -static void -test_To_String(TestBatchRunner *runner) { - String *true_string = Bool_To_String(CFISH_TRUE); - String *false_string = Bool_To_String(CFISH_FALSE); - - TEST_TRUE(runner, Str_Equals_Utf8(true_string, "true", 4), - "Bool_To_String [true]"); - TEST_TRUE(runner, Str_Equals_Utf8(false_string, "false", 5), - "Bool_To_String [false]"); - - DECREF(false_string); - DECREF(true_string); -} - -static void -test_accessors(TestBatchRunner *runner) { - TEST_INT_EQ(runner, Bool_Get_Value(CFISH_TRUE), true, - "Bool_Get_Value [true]"); - TEST_INT_EQ(runner, Bool_Get_Value(CFISH_FALSE), false, - "Bool_Get_Value [false]"); -} - -static void -test_Equals_and_Compare_To(TestBatchRunner *runner) { - TEST_TRUE(runner, Bool_Equals(CFISH_TRUE, (Obj*)CFISH_TRUE), - "CFISH_TRUE Equals itself"); - TEST_TRUE(runner, Bool_Equals(CFISH_FALSE, (Obj*)CFISH_FALSE), - "CFISH_FALSE Equals itself"); - TEST_FALSE(runner, Bool_Equals(CFISH_FALSE, (Obj*)CFISH_TRUE), - "CFISH_FALSE not Equals CFISH_TRUE "); - TEST_FALSE(runner, Bool_Equals(CFISH_TRUE, (Obj*)CFISH_FALSE), - "CFISH_TRUE not Equals CFISH_FALSE "); - TEST_FALSE(runner, Bool_Equals(CFISH_TRUE, (Obj*)STRING), - "CFISH_TRUE not Equals random other object "); -} - -static void -test_Clone(TestBatchRunner *runner) { - TEST_TRUE(runner, Bool_Equals(CFISH_TRUE, (Obj*)Bool_Clone(CFISH_TRUE)), - "Boolean Clone"); -} - -void -TestBoolean_Run_IMP(TestBoolean *self, TestBatchRunner *runner) { - TestBatchRunner_Plan(runner, (TestBatch*)self, 12); - - // Destroying the singletons should have no effect. - Bool_Destroy(CFISH_TRUE); - Bool_Destroy(CFISH_FALSE); - - test_singleton(runner); - test_To_String(runner); - test_accessors(runner); - test_Equals_and_Compare_To(runner); - test_Clone(runner); -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestBoolean.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestBoolean.cfh b/runtime/core/Clownfish/Test/TestBoolean.cfh deleted file mode 100644 index 43702db..0000000 --- a/runtime/core/Clownfish/Test/TestBoolean.cfh +++ /dev/null @@ -1,29 +0,0 @@ -/* 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::TestBoolean - inherits Clownfish::TestHarness::TestBatch { - - inert incremented TestBoolean* - new(); - - void - Run(TestBoolean *self, TestBatchRunner *runner); -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestByteBuf.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestByteBuf.c b/runtime/core/Clownfish/Test/TestByteBuf.c deleted file mode 100644 index 7f8fc50..0000000 --- a/runtime/core/Clownfish/Test/TestByteBuf.c +++ /dev/null @@ -1,218 +0,0 @@ -/* 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. - */ - -#include <string.h> - -#define CFISH_USE_SHORT_NAMES -#define TESTCFISH_USE_SHORT_NAMES - -#include "Clownfish/Test/TestByteBuf.h" - -#include "Clownfish/ByteBuf.h" -#include "Clownfish/Test.h" -#include "Clownfish/TestHarness/TestBatchRunner.h" -#include "Clownfish/TestHarness/TestUtils.h" -#include "Clownfish/Blob.h" -#include "Clownfish/Class.h" -#include "Clownfish/Err.h" -#include "Clownfish/String.h" -#include "Clownfish/Util/Memory.h" - -#include <string.h> - -TestByteBuf* -TestBB_new() { - return (TestByteBuf*)Class_Make_Obj(TESTBYTEBUF); -} - -static void -test_new_steal_bytes(TestBatchRunner *runner) { - char *buf = (char*)MALLOCATE(10); - memset(buf, 'x', 10); - ByteBuf *bb = BB_new_steal_bytes(buf, 5, 10); - TEST_TRUE(runner, BB_Get_Buf(bb) == buf, "new_steal_bytes steals buffer"); - TEST_TRUE(runner, BB_Equals_Bytes(bb, "xxxxx", 5), - "new_steal_bytes sets correct size"); - BB_Set_Size(bb, 10); - TEST_TRUE(runner, BB_Equals_Bytes(bb, "xxxxxxxxxx", 10), - "new_steal_bytes sets correct capacity"); - DECREF(bb); -} - -static void -test_Equals(TestBatchRunner *runner) { - ByteBuf *bb = BB_new_bytes("foo", 4); // Include terminating NULL. - - TEST_TRUE(runner, BB_Equals(bb, (Obj*)bb), "Equals self"); - TEST_FALSE(runner, BB_Equals(bb, (Obj*)BYTEBUF), - "Equals spoiled by different type"); - - { - ByteBuf *other = BB_new_bytes("foo", 4); - TEST_TRUE(runner, BB_Equals(bb, (Obj*)other), "Equals"); - DECREF(other); - } - - TEST_TRUE(runner, BB_Equals_Bytes(bb, "foo", 4), "Equals_Bytes"); - TEST_FALSE(runner, BB_Equals_Bytes(bb, "foo", 3), - "Equals_Bytes spoiled by different size"); - TEST_FALSE(runner, BB_Equals_Bytes(bb, "bar", 4), - "Equals_Bytes spoiled by different content"); - - { - ByteBuf *other = BB_new_bytes("foo", 3); - TEST_FALSE(runner, BB_Equals(bb, (Obj*)other), - "Different size spoils Equals"); - DECREF(other); - } - - { - ByteBuf *other = BB_new_bytes("bar", 4); - TEST_UINT_EQ(runner, BB_Get_Size(bb), BB_Get_Size(other), - "same length"); - TEST_FALSE(runner, BB_Equals(bb, (Obj*)other), - "Different content spoils Equals"); - DECREF(other); - } - - DECREF(bb); -} - -static void -test_Grow(TestBatchRunner *runner) { - ByteBuf *bb = BB_new(1); - TEST_UINT_EQ(runner, BB_Get_Capacity(bb), 8, - "Allocate in 8-byte increments"); - BB_Grow(bb, 9); - TEST_UINT_EQ(runner, BB_Get_Capacity(bb), 16, - "Grow in 8-byte increments"); - BB_Grow(bb, 16); - TEST_UINT_EQ(runner, BB_Get_Capacity(bb), 16, - "Grow to same capacity has no effect"); - DECREF(bb); -} - -static void -test_Clone(TestBatchRunner *runner) { - ByteBuf *bb = BB_new_bytes("foo", 3); - ByteBuf *twin = BB_Clone(bb); - TEST_TRUE(runner, BB_Equals(bb, (Obj*)twin), "Clone"); - DECREF(bb); - DECREF(twin); -} - -static void -test_Compare_To(TestBatchRunner *runner) { - ByteBuf *a = BB_new_bytes("foo\0a", 5); - ByteBuf *b = BB_new_bytes("foo\0b", 5); - - BB_Set_Size(a, 4); - BB_Set_Size(b, 4); - TEST_INT_EQ(runner, BB_Compare_To(a, (Obj*)b), 0, - "Compare_To returns 0 for equal ByteBufs"); - - BB_Set_Size(a, 3); - TEST_TRUE(runner, BB_Compare_To(a, (Obj*)b) < 0, - "shorter ByteBuf sorts first"); - TEST_TRUE(runner, BB_Compare_To(b, (Obj*)a) > 0, - "longer ByteBuf sorts last"); - - BB_Set_Size(a, 5); - BB_Set_Size(b, 5); - TEST_TRUE(runner, BB_Compare_To(a, (Obj*)b) < 0, - "NULL doesn't interfere with Compare_To"); - - DECREF(a); - DECREF(b); -} - -static void -test_Cat(TestBatchRunner *runner) { - ByteBuf *bb = BB_new_bytes("foo", 3); - - { - Blob *blob = Blob_new("bar", 3); - BB_Cat(bb, blob); - TEST_TRUE(runner, BB_Equals_Bytes(bb, "foobar", 6), "Cat"); - DECREF(blob); - } - - BB_Cat_Bytes(bb, "baz", 3); - TEST_TRUE(runner, BB_Equals_Bytes(bb, "foobarbaz", 9), "Cat_Bytes"); - - DECREF(bb); -} - -static void -test_Utf8_To_String(TestBatchRunner *runner) { - ByteBuf *bb = BB_new_bytes("foo", 3); - - { - String *string = BB_Utf8_To_String(bb); - TEST_TRUE(runner, Str_Equals_Utf8(string, "foo", 3), "Utf8_To_String"); - DECREF(string); - } - - { - String *string = BB_Trusted_Utf8_To_String(bb); - TEST_TRUE(runner, Str_Equals_Utf8(string, "foo", 3), - "Trusted_Utf8_To_String"); - DECREF(string); - } - - DECREF(bb); -} - -static void -S_set_wrong_size(void *context) { - ByteBuf *bb = (ByteBuf*)context; - BB_Set_Size(bb, BB_Get_Capacity(bb) + 1); -} - -static void -test_Set_Size(TestBatchRunner *runner) { - ByteBuf *bb = BB_new(10); - Err *error = Err_trap(S_set_wrong_size, bb); - TEST_TRUE(runner, error != NULL, "Setting size beyond capacity throws"); - DECREF(error); - DECREF(bb); -} - -static void -test_Yield_Blob(TestBatchRunner *runner) { - ByteBuf *bb = BB_new_bytes("alpha", 5); - Blob *blob = BB_Yield_Blob(bb); - TEST_TRUE(runner, Blob_Equals_Bytes(blob, "alpha", 5), "Yield_Blob"); - TEST_UINT_EQ(runner, BB_Get_Size(bb), 0, "Yield_Blob clears buf"); - DECREF(blob); - DECREF(bb); -} - -void -TestBB_Run_IMP(TestByteBuf *self, TestBatchRunner *runner) { - TestBatchRunner_Plan(runner, (TestBatch*)self, 27); - test_new_steal_bytes(runner); - test_Equals(runner); - test_Grow(runner); - test_Clone(runner); - test_Compare_To(runner); - test_Cat(runner); - test_Utf8_To_String(runner); - test_Set_Size(runner); - test_Yield_Blob(runner); -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestByteBuf.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestByteBuf.cfh b/runtime/core/Clownfish/Test/TestByteBuf.cfh deleted file mode 100644 index d27e715..0000000 --- a/runtime/core/Clownfish/Test/TestByteBuf.cfh +++ /dev/null @@ -1,29 +0,0 @@ -/* 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::TestByteBuf nickname TestBB - inherits Clownfish::TestHarness::TestBatch { - - inert incremented TestByteBuf* - new(); - - void - Run(TestByteBuf *self, TestBatchRunner *runner); -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestCharBuf.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestCharBuf.c b/runtime/core/Clownfish/Test/TestCharBuf.c deleted file mode 100644 index 4329987..0000000 --- a/runtime/core/Clownfish/Test/TestCharBuf.c +++ /dev/null @@ -1,394 +0,0 @@ -/* 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. - */ - -#include <string.h> -#include <stdio.h> - -#define CFISH_USE_SHORT_NAMES -#define TESTCFISH_USE_SHORT_NAMES -#define C_CFISH_CHARBUF - -#include "charmony.h" - -#include "Clownfish/Test/TestCharBuf.h" - -#include "Clownfish/CharBuf.h" -#include "Clownfish/Err.h" -#include "Clownfish/Num.h" -#include "Clownfish/String.h" -#include "Clownfish/Test.h" -#include "Clownfish/TestHarness/TestBatchRunner.h" -#include "Clownfish/TestHarness/TestUtils.h" -#include "Clownfish/Class.h" - -static char smiley[] = { (char)0xE2, (char)0x98, (char)0xBA, 0 }; -static uint32_t smiley_len = 3; - -TestCharBuf* -TestCB_new() { - return (TestCharBuf*)Class_Make_Obj(TESTCHARBUF); -} - -static CharBuf* -S_get_cb(const char *string) { - CharBuf *cb = CB_new(0); - CB_Cat_Utf8(cb, string, strlen(string)); - return cb; -} - -static String* -S_get_str(const char *string) { - return Str_new_from_utf8(string, strlen(string)); -} - -static bool -S_cb_equals(CharBuf *cb, String *other) { - String *string = CB_To_String(cb); - bool retval = Str_Equals(string, (Obj*)other); - DECREF(string); - return retval; -} - -static void -S_cat_invalid_utf8(void *context) { - CharBuf *cb = (CharBuf*)context; - CB_Cat_Utf8(cb, "\xF0" "a", 2); -} - -static void -test_Cat(TestBatchRunner *runner) { - String *wanted = Str_newf("a%s", smiley); - CharBuf *got = S_get_cb(""); - - CB_Cat(got, wanted); - TEST_TRUE(runner, S_cb_equals(got, wanted), "Cat"); - DECREF(got); - - got = S_get_cb("a"); - CB_Cat_Char(got, 0x263A); - TEST_TRUE(runner, S_cb_equals(got, wanted), "Cat_Char"); - DECREF(got); - - got = S_get_cb("a"); - CB_Cat_Utf8(got, smiley, smiley_len); - TEST_TRUE(runner, S_cb_equals(got, wanted), "Cat_Utf8"); - DECREF(got); - - got = S_get_cb("a"); - Err *error = Err_trap(S_cat_invalid_utf8, got); - TEST_TRUE(runner, error != NULL, "Cat_Utf8 throws with invalid UTF-8"); - DECREF(error); - DECREF(got); - - got = S_get_cb("a"); - CB_Cat_Trusted_Utf8(got, smiley, smiley_len); - TEST_TRUE(runner, S_cb_equals(got, wanted), "Cat_Trusted_Utf8"); - DECREF(got); - - DECREF(wanted); -} - -static void -test_Clone(TestBatchRunner *runner) { - String *wanted = S_get_str("foo"); - CharBuf *wanted_cb = S_get_cb("foo"); - CharBuf *got = CB_Clone(wanted_cb); - TEST_TRUE(runner, S_cb_equals(got, wanted), "Clone"); - DECREF(got); - DECREF(wanted); - DECREF(wanted_cb); -} - -static void -test_vcatf_percent(TestBatchRunner *runner) { - String *wanted = S_get_str("foo % bar"); - CharBuf *got = S_get_cb("foo"); - CB_catf(got, " %% bar"); - TEST_TRUE(runner, S_cb_equals(got, wanted), "%%%%"); - DECREF(wanted); - DECREF(got); -} - -static void -test_vcatf_s(TestBatchRunner *runner) { - String *wanted = S_get_str("foo bar bizzle baz"); - CharBuf *got = S_get_cb("foo "); - CB_catf(got, "bar %s baz", "bizzle"); - TEST_TRUE(runner, S_cb_equals(got, wanted), "%%s"); - DECREF(wanted); - DECREF(got); -} - -static void -S_catf_s_invalid_utf8(void *context) { - CharBuf *buf = (CharBuf*)context; - CB_catf(buf, "bar %s baz", "\x82" "abcd"); -} - -static void -test_vcatf_s_invalid_utf8(TestBatchRunner *runner) { - CharBuf *buf = S_get_cb("foo "); - Err *error = Err_trap(S_catf_s_invalid_utf8, buf); - TEST_TRUE(runner, error != NULL, "%%s with invalid UTF-8"); - DECREF(error); - DECREF(buf); -} - -static void -test_vcatf_null_string(TestBatchRunner *runner) { - String *wanted = S_get_str("foo bar [NULL] baz"); - CharBuf *got = S_get_cb("foo "); - CB_catf(got, "bar %s baz", NULL); - TEST_TRUE(runner, S_cb_equals(got, wanted), "%%s NULL"); - DECREF(wanted); - DECREF(got); -} - -static void -test_vcatf_str(TestBatchRunner *runner) { - String *wanted = S_get_str("foo bar ZEKE baz"); - String *catworthy = S_get_str("ZEKE"); - CharBuf *got = S_get_cb("foo "); - CB_catf(got, "bar %o baz", catworthy); - TEST_TRUE(runner, S_cb_equals(got, wanted), "%%o CharBuf"); - DECREF(catworthy); - DECREF(wanted); - DECREF(got); -} - -static void -test_vcatf_obj(TestBatchRunner *runner) { - String *wanted = S_get_str("ooga 20 booga"); - Integer *i64 = Int_new(20); - CharBuf *got = S_get_cb("ooga"); - CB_catf(got, " %o booga", i64); - TEST_TRUE(runner, S_cb_equals(got, wanted), "%%o Obj"); - DECREF(i64); - DECREF(wanted); - DECREF(got); -} - -static void -test_vcatf_null_obj(TestBatchRunner *runner) { - String *wanted = S_get_str("foo bar [NULL] baz"); - CharBuf *got = S_get_cb("foo "); - CB_catf(got, "bar %o baz", NULL); - TEST_TRUE(runner, S_cb_equals(got, wanted), "%%o NULL"); - DECREF(wanted); - DECREF(got); -} - -static void -test_vcatf_i8(TestBatchRunner *runner) { - String *wanted = S_get_str("foo bar -3 baz"); - int8_t num = -3; - CharBuf *got = S_get_cb("foo "); - CB_catf(got, "bar %i8 baz", num); - TEST_TRUE(runner, S_cb_equals(got, wanted), "%%i8"); - DECREF(wanted); - DECREF(got); -} - -static void -test_vcatf_i32(TestBatchRunner *runner) { - String *wanted = S_get_str("foo bar -100000 baz"); - int32_t num = -100000; - CharBuf *got = S_get_cb("foo "); - CB_catf(got, "bar %i32 baz", num); - TEST_TRUE(runner, S_cb_equals(got, wanted), "%%i32"); - DECREF(wanted); - DECREF(got); -} - -static void -test_vcatf_i64(TestBatchRunner *runner) { - String *wanted = S_get_str("foo bar -5000000000 baz"); - int64_t num = INT64_C(-5000000000); - CharBuf *got = S_get_cb("foo "); - CB_catf(got, "bar %i64 baz", num); - TEST_TRUE(runner, S_cb_equals(got, wanted), "%%i64"); - DECREF(wanted); - DECREF(got); -} - -static void -test_vcatf_u8(TestBatchRunner *runner) { - String *wanted = S_get_str("foo bar 3 baz"); - uint8_t num = 3; - CharBuf *got = S_get_cb("foo "); - CB_catf(got, "bar %u8 baz", num); - TEST_TRUE(runner, S_cb_equals(got, wanted), "%%u8"); - DECREF(wanted); - DECREF(got); -} - -static void -test_vcatf_u32(TestBatchRunner *runner) { - String *wanted = S_get_str("foo bar 100000 baz"); - uint32_t num = 100000; - CharBuf *got = S_get_cb("foo "); - CB_catf(got, "bar %u32 baz", num); - TEST_TRUE(runner, S_cb_equals(got, wanted), "%%u32"); - DECREF(wanted); - DECREF(got); -} - -static void -test_vcatf_u64(TestBatchRunner *runner) { - String *wanted = S_get_str("foo bar 5000000000 baz"); - uint64_t num = UINT64_C(5000000000); - CharBuf *got = S_get_cb("foo "); - CB_catf(got, "bar %u64 baz", num); - TEST_TRUE(runner, S_cb_equals(got, wanted), "%%u64"); - DECREF(wanted); - DECREF(got); -} - -static void -test_vcatf_f64(TestBatchRunner *runner) { - String *wanted; - char buf[64]; - float num = 1.3f; - CharBuf *got = S_get_cb("foo "); - sprintf(buf, "foo bar %g baz", num); - wanted = Str_new_from_trusted_utf8(buf, strlen(buf)); - CB_catf(got, "bar %f64 baz", num); - TEST_TRUE(runner, S_cb_equals(got, wanted), "%%f64"); - DECREF(wanted); - DECREF(got); -} - -static void -test_vcatf_x32(TestBatchRunner *runner) { - String *wanted; - char buf[64]; - unsigned long num = INT32_MAX; - CharBuf *got = S_get_cb("foo "); -#if (CHY_SIZEOF_LONG == 4) - sprintf(buf, "foo bar %.8lx baz", num); -#elif (CHY_SIZEOF_INT == 4) - sprintf(buf, "foo bar %.8x baz", (unsigned)num); -#endif - wanted = Str_new_from_trusted_utf8(buf, strlen(buf)); - CB_catf(got, "bar %x32 baz", (uint32_t)num); - TEST_TRUE(runner, S_cb_equals(got, wanted), "%%x32"); - DECREF(wanted); - DECREF(got); -} - -typedef struct { - CharBuf *charbuf; - const char *pattern; -} CatfContext; - -static void -S_catf_invalid_pattern(void *vcontext) { - CatfContext *context = (CatfContext*)vcontext; - CB_catf(context->charbuf, context->pattern, 0); -} - -static void -test_vcatf_invalid(TestBatchRunner *runner) { - CatfContext context; - context.charbuf = S_get_cb("foo "); - - static const char *const patterns[] = { - "bar %z baz", - "bar %i baz", - "bar %i1 baz", - "bar %i33 baz", - "bar %i65 baz", - "bar %u baz", - "bar %u9 baz", - "bar %u33 baz", - "bar %u65 baz", - "bar %x baz", - "bar %x9 baz", - "bar %x33 baz", - "bar %f baz", - "bar %f9 baz", - "bar %f65 baz", - "bar \xC2 baz" - }; - static const size_t num_patterns = sizeof(patterns) / sizeof(patterns[0]); - - for (size_t i = 0; i < num_patterns; i++) { - context.pattern = patterns[i]; - Err *error = Err_trap(S_catf_invalid_pattern, &context); - TEST_TRUE(runner, error != NULL, - "catf throws with invalid pattern '%s'", patterns[i]); - DECREF(error); - } - - DECREF(context.charbuf); -} - -static void -test_Clear(TestBatchRunner *runner) { - CharBuf *cb = S_get_cb("foo"); - CB_Clear(cb); - CB_Cat_Utf8(cb, "bar", 3); - String *string = CB_Yield_String(cb); - TEST_TRUE(runner, Str_Equals_Utf8(string, "bar", 3), "Clear"); - DECREF(string); - DECREF(cb); -} - -static void -test_Grow(TestBatchRunner *runner) { - CharBuf *cb = S_get_cb("omega"); - CB_Grow(cb, 100); - size_t cap = cb->cap; - TEST_TRUE(runner, cap >= 100, "Grow"); - CB_Grow(cb, 100); - TEST_UINT_EQ(runner, cb->cap, cap, "Grow to same size has no effect"); - DECREF(cb); -} - -static void -test_Get_Size(TestBatchRunner *runner) { - CharBuf *got = S_get_cb("a"); - CB_Cat_Utf8(got, smiley, smiley_len); - TEST_UINT_EQ(runner, CB_Get_Size(got), smiley_len + 1, "Get_Size"); - DECREF(got); -} - -void -TestCB_Run_IMP(TestCharBuf *self, TestBatchRunner *runner) { - TestBatchRunner_Plan(runner, (TestBatch*)self, 41); - test_vcatf_percent(runner); - test_vcatf_s(runner); - test_vcatf_s_invalid_utf8(runner); - test_vcatf_null_string(runner); - test_vcatf_str(runner); - test_vcatf_obj(runner); - test_vcatf_null_obj(runner); - test_vcatf_i8(runner); - test_vcatf_i32(runner); - test_vcatf_i64(runner); - test_vcatf_u8(runner); - test_vcatf_u32(runner); - test_vcatf_u64(runner); - test_vcatf_f64(runner); - test_vcatf_x32(runner); - test_vcatf_invalid(runner); - test_Cat(runner); - test_Clone(runner); - test_Clear(runner); - test_Grow(runner); - test_Get_Size(runner); -} - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestCharBuf.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestCharBuf.cfh b/runtime/core/Clownfish/Test/TestCharBuf.cfh deleted file mode 100644 index d568c14..0000000 --- a/runtime/core/Clownfish/Test/TestCharBuf.cfh +++ /dev/null @@ -1,29 +0,0 @@ -/* 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::TestCharBuf nickname TestCB - inherits Clownfish::TestHarness::TestBatch { - - inert incremented TestCharBuf* - new(); - - void - Run(TestCharBuf *self, TestBatchRunner *runner); -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestClass.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestClass.c b/runtime/core/Clownfish/Test/TestClass.c deleted file mode 100644 index a6646f8..0000000 --- a/runtime/core/Clownfish/Test/TestClass.c +++ /dev/null @@ -1,158 +0,0 @@ -/* 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. - */ - -#include <stdio.h> - -#define C_CFISH_BOOLEAN -#define C_CFISH_CLASS -#define CFISH_USE_SHORT_NAMES -#define TESTCFISH_USE_SHORT_NAMES - -#include "charmony.h" - -#include <string.h> - -#include "Clownfish/Test/TestClass.h" - -#include "Clownfish/Boolean.h" -#include "Clownfish/Class.h" -#include "Clownfish/Method.h" -#include "Clownfish/String.h" -#include "Clownfish/TestHarness/TestBatchRunner.h" -#include "Clownfish/Util/Memory.h" -#include "Clownfish/Vector.h" - -TestClass* -TestClass_new() { - return (TestClass*)Class_Make_Obj(TESTCLASS); -} - -#if DEBUG_CLASS_CONTENTS - -#include <stdio.h> - -static void -S_memdump(void *vptr, size_t size) { - unsigned char *ptr = (unsigned char*)vptr; - for (size_t i = 0; i < size; i++) { - printf("%02X ", ptr[i]); - } - printf("\n"); -} - -#endif /* DEBUG_CLASS_CONTENTS */ - -static void -test_bootstrap_idempotence(TestBatchRunner *runner) { - Class *bool_class = BOOLEAN; - uint32_t bool_class_size = BOOLEAN->class_alloc_size; - uint32_t bool_ivars_offset = cfish_Bool_IVARS_OFFSET; - Boolean *true_singleton = Bool_true_singleton; - - char *bool_class_contents = (char*)MALLOCATE(bool_class_size); - memcpy(bool_class_contents, BOOLEAN, bool_class_size); - - // Force another bootstrap run. - cfish_bootstrap_internal(1); - -#if DEBUG_CLASS_CONTENTS - printf("Before\n"); - S_memdump(bool_class_contents, bool_class_size); - printf("After\n"); - S_memdump(BOOLEAN, bool_class_size); -#endif - - TEST_TRUE(runner, bool_class == BOOLEAN, - "Boolean class pointer unchanged"); - TEST_TRUE(runner, - memcmp(bool_class_contents, BOOLEAN, bool_class_size) == 0, - "Boolean class unchanged"); - TEST_TRUE(runner, bool_ivars_offset == cfish_Bool_IVARS_OFFSET, - "Boolean ivars offset unchanged"); - TEST_TRUE(runner, true_singleton == Bool_true_singleton, - "Boolean singleton unchanged"); - - FREEMEM(bool_class_contents); -} - -static String* -MyObj_To_String_IMP(Obj *self) { - UNUSED_VAR(self); - return Str_newf("delta"); -} - -static void -test_simple_subclass(TestBatchRunner *runner) { - String *class_name = SSTR_WRAP_C("Clownfish::Test::MyObj"); - Class *subclass = Class_singleton(class_name, OBJ); - - TEST_TRUE(runner, Str_Equals(Class_Get_Name(subclass), (Obj*)class_name), - "Get_Name"); - TEST_TRUE(runner, Class_Get_Parent(subclass) == OBJ, "Get_Parent"); - - Obj *obj = Class_Make_Obj(subclass); - TEST_TRUE(runner, Obj_is_a(obj, subclass), "Make_Obj"); - - Class_Override(subclass, (cfish_method_t)MyObj_To_String_IMP, - CFISH_Obj_To_String_OFFSET); - String *str = Obj_To_String(obj); - TEST_TRUE(runner, Str_Equals_Utf8(str, "delta", 5), "Override"); - DECREF(str); - - DECREF(obj); -} - -static void -test_add_alias_to_registry(TestBatchRunner *runner) { - static const char alias[] = "Clownfish::Test::ObjAlias"; - bool added; - - added = Class_add_alias_to_registry(OBJ, alias, sizeof(alias) - 1); - TEST_TRUE(runner, added, "add_alias_to_registry returns true"); - Class *klass = Class_fetch_class(SSTR_WRAP_C(alias)); - TEST_TRUE(runner, klass == OBJ, "add_alias_to_registry works"); - - added = Class_add_alias_to_registry(CLASS, alias, sizeof(alias) - 1); - TEST_FALSE(runner, added, "add_alias_to_registry returns false"); -} - -static void -test_Get_Methods(TestBatchRunner *runner) { - Vector *methods = Class_Get_Methods(OBJ); - Method *destroy = NULL; - - for (size_t i = 0, size = Vec_Get_Size(methods); i < size; i++) { - Method *method = (Method*)Vec_Fetch(methods, i); - - if (Str_Equals_Utf8(Method_Get_Name(method), "Destroy", 7)) { - destroy = method; - } - } - - TEST_TRUE(runner, destroy != NULL, "Destroy method found"); - - DECREF(methods); -} - -void -TestClass_Run_IMP(TestClass *self, TestBatchRunner *runner) { - TestBatchRunner_Plan(runner, (TestBatch*)self, 12); - test_bootstrap_idempotence(runner); - test_simple_subclass(runner); - test_add_alias_to_registry(runner); - test_Get_Methods(runner); -} - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestClass.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestClass.cfh b/runtime/core/Clownfish/Test/TestClass.cfh deleted file mode 100644 index 615c34e..0000000 --- a/runtime/core/Clownfish/Test/TestClass.cfh +++ /dev/null @@ -1,28 +0,0 @@ -/* 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::TestClass - inherits Clownfish::TestHarness::TestBatch { - - inert incremented TestClass* - new(); - - void - Run(TestClass *self, TestBatchRunner *runner); -} - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestErr.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestErr.c b/runtime/core/Clownfish/Test/TestErr.c deleted file mode 100644 index 46ecb1e..0000000 --- a/runtime/core/Clownfish/Test/TestErr.c +++ /dev/null @@ -1,193 +0,0 @@ -/* 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/TestErr.h" - -#include "Clownfish/String.h" -#include "Clownfish/Err.h" -#include "Clownfish/Test.h" -#include "Clownfish/TestHarness/TestBatchRunner.h" -#include "Clownfish/TestHarness/TestUtils.h" -#include "Clownfish/Class.h" - -TestErr* -TestErr_new() { - return (TestErr*)Class_Make_Obj(TESTERR); -} - -static void -test_To_String(TestBatchRunner *runner) { - String *message = Str_newf("oops"); - Err *error = Err_new(message); - String *string = Err_To_String(error); - TEST_TRUE(runner, Str_Equals(message, (Obj*)string), - "Stringifies as message"); - DECREF(string); - DECREF(error); -} - -static void -test_Cat_Mess(TestBatchRunner *runner) { - Err *error = Err_new(Str_newf("alpha")); - Err_Cat_Mess(error, SSTR_WRAP_C("\nbeta")); - String *mess = Err_Get_Mess(error); - TEST_TRUE(runner, Str_Equals_Utf8(mess, "alpha\nbeta", 10), "Cat_Mess"); - DECREF(error); -} - -static void -test_Add_Frame(TestBatchRunner *runner) { - { - Err *error = Err_new(Str_newf("alpha")); - Err_Add_Frame(error, "source.c", 128, "function"); - String *mess = Err_Get_Mess(error); - const char *expected = "alpha\n\tfunction at source.c line 128\n"; - TEST_TRUE(runner, Str_Equals_Utf8(mess, expected, strlen(expected)), - "Add_Frame"); - DECREF(error); - } - - { - Err *error = Err_new(Str_newf("alpha\n")); - Err_Add_Frame(error, "source.c", 128, "function"); - String *mess = Err_Get_Mess(error); - const char *expected = "alpha\n\tfunction at source.c line 128\n"; - TEST_TRUE(runner, Str_Equals_Utf8(mess, expected, strlen(expected)), - "Add_Frame with trailing newline"); - DECREF(error); - } - - { - Err *error = Err_new(Str_newf("alpha")); - Err_Add_Frame(error, "source.c", 128, NULL); - String *mess = Err_Get_Mess(error); - const char *expected = "alpha\n\tat source.c line 128\n"; - TEST_TRUE(runner, Str_Equals_Utf8(mess, expected, strlen(expected)), - "Add_Frame without func"); - DECREF(error); - } -} - -static void -S_rethrow(void *context) { - Err *error = (Err*)context; - Err_rethrow(error, "src.c", 12, "fn"); -} - -static void -test_rethrow(TestBatchRunner *runner) { - Err *error = Err_new(Str_newf("error")); - Err *rethrown = Err_trap(S_rethrow, error); - String *mess = Err_Get_Mess(rethrown); - const char *expected = "error\n\tfn at src.c line 12\n"; - TEST_TRUE(runner, Str_Starts_With_Utf8(mess, expected, strlen(expected)), - "rethrow"); - DECREF(error); -} - -static void -S_invalid_downcast(void *context) { - Obj *obj = (Obj*)context; - DOWNCAST(obj, ERR); -} - -static void -test_downcast(TestBatchRunner *runner) { - Obj *obj = (Obj*)Str_newf("gamma"); - - TEST_TRUE(runner, DOWNCAST(obj, STRING) != NULL, "downcast"); - - TEST_TRUE(runner, DOWNCAST(NULL, STRING) == NULL, "downcast NULL"); - - Err *error = Err_trap(S_invalid_downcast, obj); - TEST_TRUE(runner, error != NULL, "downcast throws"); - DECREF(error); - - DECREF(obj); -} - -static void -S_invalid_certify(void *context) { - Obj *obj = (Obj*)context; - CERTIFY(obj, ERR); -} - -static void -test_certify(TestBatchRunner *runner) { - Obj *obj = (Obj*)Str_newf("epsilon"); - Err *error; - - TEST_TRUE(runner, CERTIFY(obj, STRING) != NULL, "certify"); - - error = Err_trap(S_invalid_certify, NULL); - TEST_TRUE(runner, error != NULL, "certify NULL"); - DECREF(error); - - error = Err_trap(S_invalid_certify, obj); - TEST_TRUE(runner, error != NULL, "certify throws"); - DECREF(error); - - DECREF(obj); -} - -static void -S_err_thread(void *arg) { - TestBatchRunner *runner = (TestBatchRunner*)arg; - - TEST_TRUE(runner, Err_get_error() == NULL, - "global error in thread initialized to null"); - - Err_set_error(Err_new(Str_newf("thread"))); - String *mess = Err_Get_Mess(Err_get_error()); - TEST_TRUE(runner, Str_Equals_Utf8(mess, "thread", 6), - "set_error in thread works"); -} - -static void -test_threads(TestBatchRunner *runner) { - if (!TestUtils_has_threads) { - SKIP(runner, 3, "no thread support"); - return; - } - - Err_set_error(Err_new(Str_newf("main"))); - - void *runtime = TestUtils_clone_host_runtime(); - Thread *thread = TestUtils_thread_create(S_err_thread, runner, runtime); - TestUtils_thread_join(thread); - TestUtils_destroy_host_runtime(runtime); - - String *mess = Err_Get_Mess(Err_get_error()); - TEST_TRUE(runner, Str_Equals_Utf8(mess, "main", 4), - "thread doesn't clobber global error"); -} - -void -TestErr_Run_IMP(TestErr *self, TestBatchRunner *runner) { - TestBatchRunner_Plan(runner, (TestBatch*)self, 15); - test_To_String(runner); - test_Cat_Mess(runner); - test_Add_Frame(runner); - test_rethrow(runner); - test_downcast(runner); - test_certify(runner); - test_threads(runner); -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestErr.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestErr.cfh b/runtime/core/Clownfish/Test/TestErr.cfh deleted file mode 100644 index 178017c..0000000 --- a/runtime/core/Clownfish/Test/TestErr.cfh +++ /dev/null @@ -1,28 +0,0 @@ -/* 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::TestErr - inherits Clownfish::TestHarness::TestBatch { - - inert incremented TestErr* - new(); - - void - Run(TestErr *self, TestBatchRunner *runner); -} - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestHash.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestHash.c b/runtime/core/Clownfish/Test/TestHash.c deleted file mode 100644 index b00d891..0000000 --- a/runtime/core/Clownfish/Test/TestHash.c +++ /dev/null @@ -1,325 +0,0 @@ -/* 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. - */ - -#include <stdlib.h> -#include <time.h> - -#define CFISH_USE_SHORT_NAMES -#define TESTCFISH_USE_SHORT_NAMES -#define C_CFISH_HASH - -#include "Clownfish/Test/TestHash.h" - -#include "Clownfish/String.h" -#include "Clownfish/Boolean.h" -#include "Clownfish/Hash.h" -#include "Clownfish/Test.h" -#include "Clownfish/TestHarness/TestBatchRunner.h" -#include "Clownfish/TestHarness/TestUtils.h" -#include "Clownfish/Vector.h" -#include "Clownfish/Class.h" - -TestHash* -TestHash_new() { - return (TestHash*)Class_Make_Obj(TESTHASH); -} - -static void -test_Equals(TestBatchRunner *runner) { - Hash *hash = Hash_new(0); - Hash *other = Hash_new(0); - String *stuff = SSTR_WRAP_C("stuff"); - - TEST_TRUE(runner, Hash_Equals(hash, (Obj*)other), - "Empty hashes are equal"); - - Hash_Store_Utf8(hash, "foo", 3, (Obj*)CFISH_TRUE); - TEST_FALSE(runner, Hash_Equals(hash, (Obj*)other), - "Add one pair and Equals returns false"); - - Hash_Store_Utf8(other, "foo", 3, (Obj*)CFISH_TRUE); - TEST_TRUE(runner, Hash_Equals(hash, (Obj*)other), - "Add a matching pair and Equals returns true"); - - Hash_Store_Utf8(other, "foo", 3, INCREF(stuff)); - TEST_FALSE(runner, Hash_Equals(hash, (Obj*)other), - "Non-matching value spoils Equals"); - - DECREF(hash); - DECREF(other); -} - -static void -test_Store_and_Fetch(TestBatchRunner *runner) { - Hash *hash = Hash_new(100); - Hash *dupe = Hash_new(100); - const size_t starting_cap = Hash_Get_Capacity(hash); - Vector *expected = Vec_new(100); - Vector *got = Vec_new(100); - String *twenty = SSTR_WRAP_C("20"); - String *forty = SSTR_WRAP_C("40"); - String *foo = SSTR_WRAP_C("foo"); - - for (int32_t i = 0; i < 100; i++) { - String *str = Str_newf("%i32", i); - Hash_Store(hash, str, (Obj*)str); - Hash_Store(dupe, str, INCREF(str)); - Vec_Push(expected, INCREF(str)); - } - TEST_TRUE(runner, Hash_Equals(hash, (Obj*)dupe), "Equals"); - - TEST_UINT_EQ(runner, Hash_Get_Capacity(hash), starting_cap, - "Initial capacity sufficient (no rebuilds)"); - - for (size_t i = 0; i < 100; i++) { - String *key = (String*)Vec_Fetch(expected, i); - Obj *elem = Hash_Fetch(hash, key); - Vec_Push(got, (Obj*)INCREF(elem)); - } - - TEST_TRUE(runner, Vec_Equals(got, (Obj*)expected), - "basic Store and Fetch"); - TEST_UINT_EQ(runner, Hash_Get_Size(hash), 100, - "size incremented properly by Hash_Store"); - - TEST_TRUE(runner, Hash_Fetch(hash, foo) == NULL, - "Fetch against non-existent key returns NULL"); - - String *twelve = (String*)Hash_Fetch_Utf8(hash, "12", 2); - TEST_TRUE(runner, Str_Equals_Utf8(twelve, "12", 2), "Fetch_Utf8"); - - Obj *stored_foo = INCREF(foo); - Hash_Store(hash, forty, stored_foo); - TEST_TRUE(runner, Str_Equals(foo, Hash_Fetch(hash, forty)), - "Hash_Store replaces existing value"); - TEST_FALSE(runner, Hash_Equals(hash, (Obj*)dupe), - "replacement value spoils equals"); - TEST_UINT_EQ(runner, Hash_Get_Size(hash), 100, - "size unaffected after value replaced"); - - TEST_TRUE(runner, Hash_Delete(hash, forty) == stored_foo, - "Delete returns value"); - DECREF(stored_foo); - TEST_UINT_EQ(runner, Hash_Get_Size(hash), 99, - "size decremented by successful Delete"); - TEST_TRUE(runner, Hash_Delete(hash, forty) == NULL, - "Delete returns NULL when key not found"); - TEST_UINT_EQ(runner, Hash_Get_Size(hash), 99, - "size not decremented by unsuccessful Delete"); - DECREF(Hash_Delete(dupe, forty)); - TEST_TRUE(runner, Vec_Equals(got, (Obj*)expected), "Equals after Delete"); - - Obj *forty_one = Hash_Delete_Utf8(hash, "41", 2); - TEST_TRUE(runner, forty_one != NULL, "Delete_Utf8"); - TEST_UINT_EQ(runner, Hash_Get_Size(hash), 98, - "Delete_Utf8 decrements size"); - DECREF(forty_one); - - Hash_Clear(hash); - TEST_TRUE(runner, Hash_Fetch(hash, twenty) == NULL, "Clear"); - TEST_TRUE(runner, Hash_Get_Size(hash) == 0, "size is 0 after Clear"); - - Hash_Clear(hash); - Hash_Store(hash, forty, NULL); - TEST_TRUE(runner, Hash_Fetch(hash, forty) == NULL, "Store NULL"); - TEST_TRUE(runner, Hash_Get_Size(hash) == 1, "Size after Store NULL"); - TEST_TRUE(runner, Hash_Delete(hash, forty) == NULL, "Delete NULL value"); - TEST_TRUE(runner, Hash_Get_Size(hash) == 0, - "Size after Deleting NULL val"); - - DECREF(hash); - DECREF(dupe); - DECREF(got); - DECREF(expected); -} - -static void -test_Keys_Values(TestBatchRunner *runner) { - Hash *hash = Hash_new(0); // trigger multiple rebuilds. - Vector *expected = Vec_new(100); - Vector *keys; - Vector *values; - - for (uint32_t i = 0; i < 500; i++) { - String *str = Str_newf("%u32", i); - Hash_Store(hash, str, (Obj*)str); - Vec_Push(expected, INCREF(str)); - } - - Vec_Sort(expected); - - keys = Hash_Keys(hash); - values = Hash_Values(hash); - Vec_Sort(keys); - Vec_Sort(values); - TEST_TRUE(runner, Vec_Equals(keys, (Obj*)expected), "Keys"); - TEST_TRUE(runner, Vec_Equals(values, (Obj*)expected), "Values"); - Vec_Clear(keys); - Vec_Clear(values); - - { - String *forty = SSTR_WRAP_C("40"); - String *nope = SSTR_WRAP_C("nope"); - TEST_TRUE(runner, Hash_Has_Key(hash, forty), "Has_Key"); - TEST_FALSE(runner, Hash_Has_Key(hash, nope), - "Has_Key returns false for non-existent key"); - } - - DECREF(hash); - DECREF(expected); - DECREF(keys); - DECREF(values); -} - -static void -test_stress(TestBatchRunner *runner) { - Hash *hash = Hash_new(0); // trigger multiple rebuilds. - Vector *expected = Vec_new(1000); - Vector *keys; - Vector *values; - - for (uint32_t i = 0; i < 1000; i++) { - String *str = TestUtils_random_string((size_t)(rand() % 1200)); - while (Hash_Fetch(hash, str)) { - DECREF(str); - str = TestUtils_random_string((size_t)(rand() % 1200)); - } - Hash_Store(hash, str, (Obj*)str); - Vec_Push(expected, INCREF(str)); - } - - Vec_Sort(expected); - - // Overwrite for good measure. - for (uint32_t i = 0; i < 1000; i++) { - String *str = (String*)Vec_Fetch(expected, i); - Hash_Store(hash, str, INCREF(str)); - } - - keys = Hash_Keys(hash); - values = Hash_Values(hash); - Vec_Sort(keys); - Vec_Sort(values); - TEST_TRUE(runner, Vec_Equals(keys, (Obj*)expected), "stress Keys"); - TEST_TRUE(runner, Vec_Equals(values, (Obj*)expected), "stress Values"); - - DECREF(keys); - DECREF(values); - DECREF(expected); - DECREF(hash); -} - -static void -test_collision(TestBatchRunner *runner) { - Hash *hash = Hash_new(0); - String *one = Str_newf("A"); - String *two = Str_newf("P{2}|=~-ULE/d"); - - TEST_TRUE(runner, Str_Hash_Sum(one) == Str_Hash_Sum(two), - "Keys have the same hash sum"); - - Hash_Store(hash, one, INCREF(one)); - Hash_Store(hash, two, INCREF(two)); - String *elem = (String*)Hash_Fetch(hash, two); - TEST_TRUE(runner, elem == two, "Fetch works with collisions"); - - DECREF(one); - DECREF(two); - DECREF(hash); -} - -static void -test_store_skips_tombstone(TestBatchRunner *runner) { - Hash *hash = Hash_new(0); - size_t mask = Hash_Get_Capacity(hash) - 1; - - String *one = Str_newf("one"); - size_t slot = Str_Hash_Sum(one) & mask; - - // Find a colliding key. - String *two = NULL; - for (int i = 0; i < 100000; i++) { - two = Str_newf("%i32", i); - if (slot == (Str_Hash_Sum(two) & mask)) { - break; - } - DECREF(two); - two = NULL; - } - - Hash_Store(hash, one, (Obj*)CFISH_TRUE); - Hash_Store(hash, two, (Obj*)CFISH_TRUE); - Hash_Delete(hash, one); - Hash_Store(hash, two, (Obj*)CFISH_TRUE); - - TEST_UINT_EQ(runner, Hash_Get_Size(hash), 1, "Store skips tombstone"); - - DECREF(one); - DECREF(two); - DECREF(hash); -} - -static void -test_threshold_accounting(TestBatchRunner *runner) { - Hash *hash = Hash_new(20); - String *key = Str_newf("key"); - - size_t threshold = hash->threshold; - Hash_Store(hash, key, (Obj*)CFISH_TRUE); - Hash_Delete(hash, key); - TEST_UINT_EQ(runner, hash->threshold, threshold - 1, - "Tombstone creation decreases threshold"); - - Hash_Store(hash, key, (Obj*)CFISH_TRUE); - TEST_UINT_EQ(runner, hash->threshold, threshold, - "Tombstone destruction increases threshold"); - - DECREF(key); - DECREF(hash); -} - -static void -test_tombstone_identification(TestBatchRunner *runner) { - Hash *hash = Hash_new(20); - String *key = Str_newf("P{2}|=~-U@!y>"); - - // Tombstones have a zero hash_sum. - TEST_UINT_EQ(runner, Str_Hash_Sum(key), 0, "Key has zero hash sum"); - - Hash_Store(hash, key, (Obj*)CFISH_TRUE); - Hash_Delete(hash, key); - TEST_TRUE(runner, Hash_Fetch(hash, key) == NULL, - "Key with zero hash sum isn't mistaken for tombstone"); - - DECREF(key); - DECREF(hash); -} - -void -TestHash_Run_IMP(TestHash *self, TestBatchRunner *runner) { - TestBatchRunner_Plan(runner, (TestBatch*)self, 39); - srand((unsigned int)time((time_t*)NULL)); - test_Equals(runner); - test_Store_and_Fetch(runner); - test_Keys_Values(runner); - test_stress(runner); - test_collision(runner); - test_store_skips_tombstone(runner); - test_threshold_accounting(runner); - test_tombstone_identification(runner); -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestHash.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestHash.cfh b/runtime/core/Clownfish/Test/TestHash.cfh deleted file mode 100644 index a730105..0000000 --- a/runtime/core/Clownfish/Test/TestHash.cfh +++ /dev/null @@ -1,29 +0,0 @@ -/* 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::TestHash - inherits Clownfish::TestHarness::TestBatch { - - inert incremented TestHash* - new(); - - void - Run(TestHash *self, TestBatchRunner *runner); -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestHashIterator.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestHashIterator.c b/runtime/core/Clownfish/Test/TestHashIterator.c deleted file mode 100644 index fac7d69..0000000 --- a/runtime/core/Clownfish/Test/TestHashIterator.c +++ /dev/null @@ -1,253 +0,0 @@ -/* 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. - */ - -#include <stdlib.h> -#include <time.h> - -#define CFISH_USE_SHORT_NAMES -#define TESTCFISH_USE_SHORT_NAMES - -#include "Clownfish/Test/TestHashIterator.h" - -#include "Clownfish/Err.h" -#include "Clownfish/String.h" -#include "Clownfish/Hash.h" -#include "Clownfish/HashIterator.h" -#include "Clownfish/Test.h" -#include "Clownfish/Vector.h" -#include "Clownfish/TestHarness/TestBatchRunner.h" -#include "Clownfish/TestHarness/TestUtils.h" -#include "Clownfish/Class.h" - -TestHashIterator* -TestHashIterator_new() { - return (TestHashIterator*)Class_Make_Obj(TESTHASHITERATOR); -} - -static void -test_Next(TestBatchRunner *runner) { - Hash *hash = Hash_new(0); // trigger multiple rebuilds. - Vector *expected = Vec_new(100); - Vector *keys = Vec_new(500); - Vector *values = Vec_new(500); - - for (uint32_t i = 0; i < 500; i++) { - String *str = Str_newf("%u32", i); - Hash_Store(hash, str, (Obj*)str); - Vec_Push(expected, INCREF(str)); - } - - Vec_Sort(expected); - - { - HashIterator *iter = HashIter_new(hash); - while (HashIter_Next(iter)) { - String *key = HashIter_Get_Key(iter); - Obj *value = HashIter_Get_Value(iter); - Vec_Push(keys, INCREF(key)); - Vec_Push(values, INCREF(value)); - } - TEST_TRUE(runner, !HashIter_Next(iter), - "Next continues to return false after iteration finishes."); - - DECREF(iter); - } - - Vec_Sort(keys); - Vec_Sort(values); - TEST_TRUE(runner, Vec_Equals(keys, (Obj*)expected), "Keys from Iter"); - TEST_TRUE(runner, Vec_Equals(values, (Obj*)expected), "Values from Iter"); - - DECREF(hash); - DECREF(expected); - DECREF(keys); - DECREF(values); -} - -static void -S_invoke_Next(void *context) { - HashIterator *iter = (HashIterator*)context; - HashIter_Next(iter); -} - -static void -S_invoke_Get_Key(void *context) { - HashIterator *iter = (HashIterator*)context; - HashIter_Get_Key(iter); -} - -static void -S_invoke_Get_Value(void *context) { - HashIterator *iter = (HashIterator*)context; - HashIter_Get_Value(iter); -} - -static void -test_empty(TestBatchRunner *runner) { - Hash *hash = Hash_new(0); - HashIterator *iter = HashIter_new(hash); - - TEST_TRUE(runner, !HashIter_Next(iter), - "First call to next false on empty hash iteration"); - - Err *get_key_error = Err_trap(S_invoke_Get_Key, iter); - TEST_TRUE(runner, get_key_error != NULL, - "Get_Key throws exception on empty hash."); - DECREF(get_key_error); - - Err *get_value_error = Err_trap(S_invoke_Get_Value, iter); - TEST_TRUE(runner, get_value_error != NULL, - "Get_Value throws exception on empty hash."); - DECREF(get_value_error); - - DECREF(hash); - DECREF(iter); -} - -static void -test_Get_Key_and_Get_Value(TestBatchRunner *runner) { - Hash *hash = Hash_new(0); - String *str = Str_newf("foo"); - Hash_Store(hash, str, (Obj*)str); - bool ok; - - HashIterator *iter = HashIter_new(hash); - DECREF(hash); - - Err *get_key_error = Err_trap(S_invoke_Get_Key, iter); - TEST_TRUE(runner, get_key_error != NULL, - "Get_Key throws exception before first call to Next."); - ok = Str_Contains_Utf8(Err_Get_Mess(get_key_error), "before", 6); - TEST_TRUE(runner, ok, "Get_Key before Next throws correct message"); - DECREF(get_key_error); - - Err *get_value_error = Err_trap(S_invoke_Get_Value, iter); - TEST_TRUE(runner, get_value_error != NULL, - "Get_Value throws exception before first call to Next."); - ok = Str_Contains_Utf8(Err_Get_Mess(get_value_error), "before", 6); - TEST_TRUE(runner, ok, "Get_Value before Next throws correct message"); - DECREF(get_value_error); - - HashIter_Next(iter); - TEST_TRUE(runner, HashIter_Get_Key(iter) != NULL, - "Get_Key during iteration."); - TEST_TRUE(runner, HashIter_Get_Value(iter) != NULL, - "Get_Value during iteration."); - - HashIter_Next(iter); - get_key_error = Err_trap(S_invoke_Get_Key, iter); - TEST_TRUE(runner, get_key_error != NULL, - "Get_Key throws exception after end of iteration."); - ok = Str_Contains_Utf8(Err_Get_Mess(get_key_error), "after", 5); - TEST_TRUE(runner, ok, "Get_Key after end throws correct message"); - DECREF(get_key_error); - - get_value_error = Err_trap(S_invoke_Get_Value, iter); - TEST_TRUE(runner, get_value_error != NULL, - "Get_Value throws exception after end of iteration."); - ok = Str_Contains_Utf8(Err_Get_Mess(get_value_error), "after", 5); - TEST_TRUE(runner, ok, "Get_Value after end throws correct message"); - DECREF(get_value_error); - - - DECREF(iter); -} - -static void -test_illegal_modification(TestBatchRunner *runner) { - Hash *hash = Hash_new(0); - - for (uint32_t i = 0; i < 3; i++) { - String *str = Str_newf("%u32", i); - Hash_Store(hash, str, (Obj*)str); - } - - HashIterator *iter = HashIter_new(hash); - HashIter_Next(iter); - - for (uint32_t i = 0; i < 100; i++) { - String *str = Str_newf("foo %u32", i); - Hash_Store(hash, str, (Obj*)str); - } - - Err *next_error = Err_trap(S_invoke_Next, iter); - TEST_TRUE(runner, next_error != NULL, - "Next on resized hash throws exception."); - DECREF(next_error); - - Err *get_key_error = Err_trap(S_invoke_Get_Key, iter); - TEST_TRUE(runner, get_key_error != NULL, - "Get_Key on resized hash throws exception."); - DECREF(get_key_error); - - Err *get_value_error = Err_trap(S_invoke_Get_Value, iter); - TEST_TRUE(runner, get_value_error != NULL, - "Get_Value on resized hash throws exception."); - DECREF(get_value_error); - - DECREF(hash); - DECREF(iter); -} - -static void -test_tombstone(TestBatchRunner *runner) { - { - Hash *hash = Hash_new(0); - String *str = Str_newf("foo"); - Hash_Store(hash, str, INCREF(str)); - DECREF(Hash_Delete(hash, str)); - DECREF(str); - - HashIterator *iter = HashIter_new(hash); - TEST_TRUE(runner, !HashIter_Next(iter), "Next advances past tombstones."); - - DECREF(iter); - DECREF(hash); - } - - { - Hash *hash = Hash_new(0); - String *str = Str_newf("foo"); - Hash_Store(hash, str, INCREF(str)); - - HashIterator *iter = HashIter_new(hash); - HashIter_Next(iter); - DECREF(Hash_Delete(hash, str)); - - - Err *get_key_error = Err_trap(S_invoke_Get_Key, iter); - TEST_TRUE(runner, get_key_error != NULL, - "Get_Key doesn't return tombstone and throws error."); - DECREF(get_key_error); - - DECREF(str); - DECREF(iter); - DECREF(hash); - } -} - -void -TestHashIterator_Run_IMP(TestHashIterator *self, TestBatchRunner *runner) { - TestBatchRunner_Plan(runner, (TestBatch*)self, 21); - srand((unsigned int)time((time_t*)NULL)); - test_Next(runner); - test_empty(runner); - test_Get_Key_and_Get_Value(runner); - test_illegal_modification(runner); - test_tombstone(runner); -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8ba4e619/runtime/core/Clownfish/Test/TestHashIterator.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestHashIterator.cfh b/runtime/core/Clownfish/Test/TestHashIterator.cfh deleted file mode 100644 index 4765f76..0000000 --- a/runtime/core/Clownfish/Test/TestHashIterator.cfh +++ /dev/null @@ -1,29 +0,0 @@ -/* 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::TestHashIterator - inherits Clownfish::TestHarness::TestBatch { - - inert incremented TestHashIterator* - new(); - - void - Run(TestHashIterator *self, TestBatchRunner *runner); -} - -