create and delete with certificate and key
This commit is contained in:
@@ -7,8 +7,11 @@ AM_CXXFLAGS += -I ${top_srcdir}/src
|
||||
AM_LDFLAGS = -L${top_builddir}/src
|
||||
LDADD = -lcppunit
|
||||
|
||||
check_PROGRAMS=
|
||||
check_PROGRAMS = sharedpointer_test
|
||||
TESTS=${check_PROGRAMS}
|
||||
|
||||
sharedpointer_test_SOURCES = sharedpointer_test.cxx
|
||||
sharedpointer_test_LDFLAGS = -lcryptoki++
|
||||
|
||||
CLEANFILES =
|
||||
MAINTAINERCLEANFILES = makefile.in
|
||||
|
111
test/sharedpointer_test.cxx
Normal file
111
test/sharedpointer_test.cxx
Normal file
@@ -0,0 +1,111 @@
|
||||
/*! @file
|
||||
|
||||
@id $Id$
|
||||
*/
|
||||
// 1 2 3 4 5 6 7 8
|
||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
|
||||
#include <cryptoki.hxx>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <cppunit/XmlOutputter.h>
|
||||
#include <fstream>
|
||||
|
||||
using namespace cryptoki;
|
||||
|
||||
template <typename T> class SharedPointerInside: public SharedPointer<T> {
|
||||
public:
|
||||
SharedPointerInside() {}
|
||||
SharedPointerInside(const SharedPointerInside& o):
|
||||
SharedPointer<T>(o) {}
|
||||
SharedPointerInside(T* p): SharedPointer<T>(p) {}
|
||||
~SharedPointerInside() {
|
||||
SmartResource::destruct();
|
||||
}
|
||||
SharedPointerInside& operator=(const SharedPointerInside& o) {
|
||||
return reset(o), *this;
|
||||
}
|
||||
SharedPointerInside& operator=(T* p) {
|
||||
return reset(p), *this;
|
||||
}
|
||||
int cnt() {
|
||||
return SharedPointer<T>::cnt();
|
||||
}
|
||||
static int freed() {
|
||||
return _free;
|
||||
}
|
||||
protected:
|
||||
void free() {
|
||||
++_free;
|
||||
SharedPointer<T>::free();
|
||||
}
|
||||
private:
|
||||
static int _free;
|
||||
};
|
||||
|
||||
template<typename T> int SharedPointerInside<T>::_free(0);
|
||||
|
||||
class SharedPointerTest: public CppUnit::TestFixture {
|
||||
public:
|
||||
void check() {
|
||||
{
|
||||
SharedPointerInside<int> i, j(new int);
|
||||
CPPUNIT_ASSERT_EQUAL(0, SharedPointerInside<int>::freed());
|
||||
CPPUNIT_ASSERT_EQUAL(1, i.cnt());
|
||||
CPPUNIT_ASSERT_EQUAL(1, j.cnt());
|
||||
i = j;
|
||||
CPPUNIT_ASSERT_EQUAL(1, SharedPointerInside<int>::freed());
|
||||
CPPUNIT_ASSERT_EQUAL(i.get(), j.get());
|
||||
CPPUNIT_ASSERT_EQUAL(2, i.cnt());
|
||||
CPPUNIT_ASSERT_EQUAL(2, j.cnt());
|
||||
*i = 5;
|
||||
CPPUNIT_ASSERT_EQUAL(1, SharedPointerInside<int>::freed());
|
||||
CPPUNIT_ASSERT_EQUAL(5, *j);
|
||||
CPPUNIT_ASSERT_EQUAL(2, i.cnt());
|
||||
CPPUNIT_ASSERT_EQUAL(2, j.cnt());
|
||||
int* old(j.get());
|
||||
i = new int(6);
|
||||
CPPUNIT_ASSERT_EQUAL(1, SharedPointerInside<int>::freed());
|
||||
CPPUNIT_ASSERT_EQUAL(5, *j);
|
||||
CPPUNIT_ASSERT_EQUAL(6, *i);
|
||||
CPPUNIT_ASSERT(i.get()!=j.get());
|
||||
CPPUNIT_ASSERT_EQUAL(1, i.cnt());
|
||||
CPPUNIT_ASSERT_EQUAL(1, j.cnt());
|
||||
i = new int(8);
|
||||
CPPUNIT_ASSERT_EQUAL(2, SharedPointerInside<int>::freed());
|
||||
CPPUNIT_ASSERT_EQUAL(5, *j);
|
||||
CPPUNIT_ASSERT_EQUAL(8, *i);
|
||||
CPPUNIT_ASSERT(i.get()!=j.get());
|
||||
CPPUNIT_ASSERT_EQUAL(1, i.cnt());
|
||||
CPPUNIT_ASSERT_EQUAL(1, j.cnt());
|
||||
{
|
||||
SharedPointerInside<int> k(j);
|
||||
CPPUNIT_ASSERT_EQUAL(1, i.cnt());
|
||||
CPPUNIT_ASSERT_EQUAL(2, j.cnt());
|
||||
CPPUNIT_ASSERT_EQUAL(2, k.cnt());
|
||||
}
|
||||
CPPUNIT_ASSERT_EQUAL(2, SharedPointerInside<int>::freed());
|
||||
CPPUNIT_ASSERT_EQUAL(1, i.cnt());
|
||||
CPPUNIT_ASSERT_EQUAL(1, j.cnt());
|
||||
}
|
||||
CPPUNIT_ASSERT_EQUAL(4, SharedPointerInside<int>::freed());
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(SharedPointerTest);
|
||||
CPPUNIT_TEST(check);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(SharedPointerTest);
|
||||
|
||||
int main(int argc, char** argv) try {
|
||||
std::ofstream ofs((*argv+std::string(".xml")).c_str());
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), ofs));
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr<<"***Exception: "<<e.what()<<std::endl;
|
||||
return 1;
|
||||
}
|
Reference in New Issue
Block a user