Xerces 3 revisions.
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / MemoryStorageServiceTest.h
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "XMLObjectBaseTestCase.h"
18
19 #include <xmltooling/util/StorageService.h>
20
21 class MemoryStorageServiceTest : public CxxTest::TestSuite {
22 public:
23     void setUp() {
24     }
25     
26     void tearDown() {
27     }
28
29     void testMemoryService() {
30         auto_ptr<StorageService> storage(
31             XMLToolingConfig::getConfig().StorageServiceManager.newPlugin(MEMORY_STORAGE_SERVICE,NULL)
32             );
33
34         string data;
35         TSM_ASSERT_EQUALS("Record found in storage.", 0, storage->readString("context", "foo1", &data));
36         storage->createString("context", "foo1", "bar1", time(NULL) + 60);
37         storage->createString("context", "foo2", "bar2", time(NULL) + 60);
38         TSM_ASSERT_EQUALS("Record not found in storage.", 1, storage->readString("context", "foo1", &data));
39         TSM_ASSERT_EQUALS("Record value doesn't match.", data, "bar1");
40         TSM_ASSERT_EQUALS("Update failed.", 2, storage->updateString("context", "foo2", "bar1", 0, 1));
41         TSM_ASSERT_EQUALS("Record not found in storage.", 2, storage->readString("context", "foo2", &data, NULL, 1));
42         TSM_ASSERT_EQUALS("Record value doesn't match.", data, "bar1");
43         TSM_ASSERT("Delete failed.", storage->deleteString("context", "foo2"));
44         storage->reap("context");
45     }
46 };