You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2012/04/17 02:50:50 UTC
[lucy-commits] svn commit: r1326849 - in /lucy/trunk: core/Lucy/Test/Object/TestObj.c
perl/t/binding/019-obj.t
Author: marvin
Date: Tue Apr 17 00:50:49 2012
New Revision: 1326849
URL: http://svn.apache.org/viewvc?rev=1326849&view=rev
Log:
Port tests of abstract Obj routines to C.
Port existing tests and expand testing to all abstract routines of Obj.
Modified:
lucy/trunk/core/Lucy/Test/Object/TestObj.c
lucy/trunk/perl/t/binding/019-obj.t
Modified: lucy/trunk/core/Lucy/Test/Object/TestObj.c
URL: http://svn.apache.org/viewvc/lucy/trunk/core/Lucy/Test/Object/TestObj.c?rev=1326849&r1=1326848&r2=1326849&view=diff
==============================================================================
--- lucy/trunk/core/Lucy/Test/Object/TestObj.c (original)
+++ lucy/trunk/core/Lucy/Test/Object/TestObj.c Tue Apr 17 00:50:49 2012
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <stdio.h>
+
#define C_LUCY_TESTOBJ
#include "Lucy/Util/ToolSet.h"
@@ -113,10 +115,78 @@ test_Is_A(TestBatch *batch) {
DECREF(charbuf);
}
+static void
+S_attempt_init(void *context) {
+ Obj_init((Obj*)context);
+}
+
+static void
+S_attempt_Clone(void *context) {
+ Obj_Clone((Obj*)context);
+}
+
+static void
+S_attempt_Make(void *context) {
+ Obj_Make((Obj*)context);
+}
+
+static void
+S_attempt_Compare_To(void *context) {
+ Obj_Compare_To((Obj*)context, (Obj*)context);
+}
+
+static void
+S_attempt_To_I64(void *context) {
+ Obj_To_I64((Obj*)context);
+}
+
+static void
+S_attempt_To_F64(void *context) {
+ Obj_To_F64((Obj*)context);
+}
+
+static void
+S_attempt_Load(void *context) {
+ Obj_Load((Obj*)context, (Obj*)context);
+}
+
+static void
+S_attempt_Mimic(void *context) {
+ Obj_Mimic((Obj*)context, (Obj*)context);
+}
+
+static void
+S_verify_abstract_error(TestBatch *batch, Err_attempt_t routine,
+ void *context, const char *name) {
+ char message[100];
+ sprintf(message, "%s() is abstract", name);
+ Err *error = Err_trap(routine, context);
+ TEST_TRUE(batch, error != NULL
+ && Err_Is_A(error, ERR)
+ && CB_Find_Str(Err_Get_Mess(error), "bstract", 7) != -1,
+ message);
+ DECREF(error);
+}
+
+static void
+test_abstract_routines(TestBatch *batch) {
+ Obj *blank = VTable_Make_Obj(OBJ);
+ S_verify_abstract_error(batch, S_attempt_init, blank, "init");
+
+ Obj *obj = S_new_testobj();
+ S_verify_abstract_error(batch, S_attempt_Clone, obj, "Clone");
+ S_verify_abstract_error(batch, S_attempt_Make, obj, "Make");
+ S_verify_abstract_error(batch, S_attempt_Compare_To, obj, "Compare_To");
+ S_verify_abstract_error(batch, S_attempt_To_I64, obj, "To_I64");
+ S_verify_abstract_error(batch, S_attempt_To_F64, obj, "To_F64");
+ S_verify_abstract_error(batch, S_attempt_Load, obj, "Load");
+ S_verify_abstract_error(batch, S_attempt_Mimic, obj, "Mimic");
+ DECREF(obj);
+}
void
TestObj_run_tests() {
- TestBatch *batch = TestBatch_new(12);
+ TestBatch *batch = TestBatch_new(20);
TestBatch_Plan(batch);
@@ -126,6 +196,7 @@ TestObj_run_tests() {
test_Equals(batch);
test_Hash_Sum(batch);
test_Is_A(batch);
+ test_abstract_routines(batch);
DECREF(batch);
}
Modified: lucy/trunk/perl/t/binding/019-obj.t
URL: http://svn.apache.org/viewvc/lucy/trunk/perl/t/binding/019-obj.t?rev=1326849&r1=1326848&r2=1326849&view=diff
==============================================================================
--- lucy/trunk/perl/t/binding/019-obj.t (original)
+++ lucy/trunk/perl/t/binding/019-obj.t Tue Apr 17 00:50:49 2012
@@ -16,7 +16,7 @@
use strict;
use warnings;
-use Test::More tests => 20;
+use Test::More tests => 18;
package TestObj;
use base qw( Lucy::Object::Obj );
@@ -65,18 +65,10 @@ ok( defined $TestObj::version,
. "package globals in the Lucy:: namespace"
);
-# TODO: Port this test to C.
-eval { my $foo = Lucy::Object::Obj->new };
-like( $@, qr/abstract/i, "Obj is an abstract class" );
-
my $object = TestObj->new;
isa_ok( $object, "Lucy::Object::Obj",
"Clownfish objects can be subclassed outside the Lucy hierarchy" );
-# TODO: Port this test to C.
-eval { my $twin = $object->clone };
-like( $@, qr/abstract/i, "clone throws an abstract method exception" );
-
ok( $object->is_a("Lucy::Object::Obj"), "custom is_a correct" );
ok( !$object->is_a("Lucy::Object"), "custom is_a too long" );
ok( !$object->is_a("Lucy"), "custom is_a substring" );