~dobey/shardbridge/trunk

« back to all changes in this revision

Viewing changes to src/test-shardbridge.vala

  • Committer: Rodney Dawes
  • Date: 2011-12-26 21:06:50 UTC
  • Revision ID: dobey@wayofthemonkey.com-20111226210650-7r87fr2456k1paes
Allow Document content and revision to be null
Allow Document.get_content_string to return null
Implement Database.delete_doc, and test it

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
                                assert (found == true);
98
98
                        }
99
99
                });
 
100
 
 
101
        Test.add_func ("/ShardBridge/Database/delete_then_put", () => {
 
102
                        var db = new Database (null, Database.Mode.READWRITE);
 
103
                        assert (db is Database);
 
104
 
 
105
                        var doc1 = new Document ("DOC-1", "rev:0", SIMPLE_DOC);
 
106
                        assert (doc1 is Document);
 
107
                        assert (db.put_doc (doc1) != null);
 
108
                        assert (db.delete_doc (doc1) != null);
 
109
                        assert (doc1.content == null);
 
110
                        assert (doc1.get_content_string () == null);
 
111
 
 
112
                        var nodoc = db.get_doc (doc1.id);
 
113
                        assert (nodoc.content == null);
 
114
                        assert (nodoc.get_content_string () == null);
 
115
 
 
116
                        doc1.set_content_string (NESTED_DOC);
 
117
                        db.put_doc (doc1);
 
118
 
 
119
                        var doc2 = db.get_doc (doc1.id);
 
120
                        assert (doc2.get_content_string () == NESTED_DOC);
 
121
                });
100
122
}
101
123
 
102
124
void add_document_tests () {
103
125
        Test.add_func ("/ShardBridge/Document/new/success", () => {
104
 
                        Document o = null;
105
 
                        var expected = ("{\n" +
106
 
                                                        "  \"foo\" : \"bar\",\n" +
107
 
                                                        "  \"bar\" : {\n" +
108
 
                                                        "    \"baz\" : \"beez\"\n" +
109
 
                                                        "  }\n" +
110
 
                                                        "}");
111
 
                        try {
112
 
                                o = new Document ("success", "rev:0", expected);
113
 
                        } catch (Error e) {
114
 
                                throw e;
115
 
                        } finally {
116
 
                                assert (o is Document);
117
 
                                assert (expected == o.get_content_string ());
118
 
                        }
 
126
                        var o = new Document ("success", "rev:0", NESTED_DOC);
 
127
                        assert (o is Document);
 
128
                        assert (NESTED_DOC == o.get_content_string ());
119
129
                });
120
130
 
121
131
        Test.add_func ("/ShardBridge/Document/new/invalid_content", () => {
132
142
        Test.add_func ("/ShardBridge/Document/new/empty", () => {
133
143
                        Document o = null;
134
144
                        try {
135
 
                                o = new Document ("empty", "rev:0", "");
 
145
                                o = new Document ("empty", "rev:0", null);
136
146
                        } catch (DataError e) {
137
147
                                throw e;
138
148
                        } finally {
139
149
                                assert (o is Document);
140
 
                                assert ("{\n}" == o.get_content_string ());
 
150
                                assert (null == o.get_content_string ());
141
151
                        }
142
152
                });
143
153