#50 - переименование + первый работающий тест
authorFedor Yudanov <fedwiz@academ.org>
Fri, 22 Mar 2013 08:03:21 +0000 (15:03 +0700)
committerFedor Yudanov <fedwiz@academ.org>
Fri, 22 Mar 2013 08:03:21 +0000 (15:03 +0700)
.idea/modules.xml
rbejdb/Makefile [new file with mode: 0644]
rbejdb/README.md [moved from rubejdb/README.md with 100% similarity]
rbejdb/extconf.rb [moved from rubejdb/extconf.rb with 50% similarity]
rbejdb/rbejdb.iml [moved from rubejdb/rubejdb.iml with 100% similarity]
rbejdb/src/rbejdb.c [moved from rubejdb/src/rubejdb.c with 83% similarity]
rbejdb/test/Makefile [new file with mode: 0644]
rbejdb/test/t1.rb [new file with mode: 0644]
rubejdb/Makefile [deleted file]

index af332ad..9962a9f 100644 (file)
@@ -4,7 +4,7 @@
     <modules>
       <module fileurl="file://$PROJECT_DIR$/luaejdb/luaejdb.iml" filepath="$PROJECT_DIR$/luaejdb/luaejdb.iml" />
       <module fileurl="file://$PROJECT_DIR$/pyejdb/pyejdb.iml" filepath="$PROJECT_DIR$/pyejdb/pyejdb.iml" />
-      <module fileurl="file://$PROJECT_DIR$/rubejdb/rubejdb.iml" filepath="$PROJECT_DIR$/rubejdb/rubejdb.iml" />
+      <module fileurl="file://$PROJECT_DIR$/rbejdb/rbejdb.iml" filepath="$PROJECT_DIR$/rbejdb/rbejdb.iml" />
       <module fileurl="file://$PROJECT_DIR$/tcejdb/tcejdb.iml" filepath="$PROJECT_DIR$/tcejdb/tcejdb.iml" />
     </modules>
   </component>
diff --git a/rbejdb/Makefile b/rbejdb/Makefile
new file mode 100644 (file)
index 0000000..ec6de8e
--- /dev/null
@@ -0,0 +1,16 @@
+
+all: build check
+
+build:
+       ruby extconf.rb
+       make -C ./build
+       make install -C ./build
+
+check:
+       make -C ./test
+
+doc:
+
+clean:
+
+.PHONY: all build check clean doc
similarity index 100%
rename from rubejdb/README.md
rename to rbejdb/README.md
similarity index 50%
rename from rubejdb/extconf.rb
rename to rbejdb/extconf.rb
index fc725c9..0ae8b9b 100644 (file)
@@ -1,5 +1,9 @@
 require "mkmf"
 
+unless have_library('tcejdb')
+  raise "EJDB C library is not installed!"
+end
+
 BUILD_DIR = 'build'
 
 unless File.exists?(BUILD_DIR)
@@ -7,4 +11,5 @@ unless File.exists?(BUILD_DIR)
 end
 
 Dir.chdir BUILD_DIR
-create_makefile("rubejdb", '../src')
\ No newline at end of file
+
+create_makefile("rbejdb", '../src')
\ No newline at end of file
similarity index 100%
rename from rubejdb/rubejdb.iml
rename to rbejdb/rbejdb.iml
similarity index 83%
rename from rubejdb/src/rubejdb.c
rename to rbejdb/src/rbejdb.c
index c0e2360..b77fffe 100644 (file)
 #include <tcejdb/ejdb_private.h>
 #include <ruby.h>
 
+#define DEFAULT_OPEN_MODE (JBOWRITER | JBOCREAT | JBOTSYNC)
+
 typedef struct {
     EJDB* ejdb;
-} RUBEJDB;
+} RBEJDB;
 
 EJDB* getEJDB(VALUE self) {
-    RUBEJDB* rejdb;
-    Data_Get_Struct(self, RUBEJDB, rejdb);
+    RBEJDB* rejdb;
+    Data_Get_Struct(self, RBEJDB, rejdb);
     return rejdb->ejdb;
 }
 
-void EJDB_free(RUBEJDB* rejdb) {
+void EJDB_free(RBEJDB* rejdb) {
     if (!rejdb->ejdb) {
         ejdbdel(rejdb->ejdb);
     }
@@ -35,12 +37,12 @@ void EJDB_free(RUBEJDB* rejdb) {
 }
 
 VALUE EJDB_alloc(VALUE klass) {
-    return Data_Wrap_Struct(klass, NULL, EJDB_free, ruby_xmalloc(sizeof(RUBEJDB)));
+    return Data_Wrap_Struct(klass, NULL, EJDB_free, ruby_xmalloc(sizeof(RBEJDB)));
 }
 
 VALUE EJDB_init(VALUE self) {
-    RUBEJDB* rejdb;
-    Data_Get_Struct(self, RUBEJDB, rejdb);
+    RBEJDB* rejdb;
+    Data_Get_Struct(self, RBEJDB, rejdb);
 
     rejdb->ejdb = ejdbnew();
     if (!rejdb->ejdb) {
@@ -64,10 +66,13 @@ VALUE EJDB_is_open(VALUE self) {
 }
 
 
-Init_rubejdb() {
+Init_rbejdb() {
     VALUE ejdbClass = rb_define_class("EJDB", rb_cObject);
     rb_define_alloc_func(ejdbClass, EJDB_alloc);
     rb_define_private_method(ejdbClass, "initialize", RUBY_METHOD_FUNC(EJDB_init), 0);
+
+    rb_define_const(ejdbClass, "DEFAULT_OPEN_MODE", INT2FIX(DEFAULT_OPEN_MODE));
+
     rb_define_method(ejdbClass, "open", RUBY_METHOD_FUNC(EJDB_open), 2);
-    rb_define_method(ejdbClass, "is_open", RUBY_METHOD_FUNC(EJDB_is_open), 0);
+    rb_define_method(ejdbClass, "is_open?", RUBY_METHOD_FUNC(EJDB_is_open), 0);
 }
\ No newline at end of file
diff --git a/rbejdb/test/Makefile b/rbejdb/test/Makefile
new file mode 100644 (file)
index 0000000..32cbb5f
--- /dev/null
@@ -0,0 +1,7 @@
+
+all: check
+
+check:
+       ruby t1.rb
+
+.PHONY: all check
diff --git a/rbejdb/test/t1.rb b/rbejdb/test/t1.rb
new file mode 100644 (file)
index 0000000..b2260af
--- /dev/null
@@ -0,0 +1,8 @@
+require "rbejdb"
+
+ejdb = EJDB.new()
+ejdb.open("zoo", EJDB::DEFAULT_OPEN_MODE)
+
+raise "Failed to open ejdb" unless ejdb.is_open?
+
+puts "CONGRATULATIONS!!! EJDB tests has passed completely!"
\ No newline at end of file
diff --git a/rubejdb/Makefile b/rubejdb/Makefile
deleted file mode 100644 (file)
index 304184e..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-
-all: doc build
-
-build:
-       ruby extconf.rb
-       make -C ./build
-
-build-dbg:
-
-check: build-dbg
-
-doc:
-
-clean:
-
-.PHONY: all build build-dbg check clean doc