| 1 |
/* |
| 2 |
* Copyright (c) 2013 SURFnet bv |
| 3 |
* All rights reserved. |
| 4 |
* |
| 5 |
* Redistribution and use in source and binary forms, with or without |
| 6 |
* modification, are permitted provided that the following conditions |
| 7 |
* are met: |
| 8 |
* 1. Redistributions of source code must retain the above copyright |
| 9 |
* notice, this list of conditions and the following disclaimer. |
| 10 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 11 |
* notice, this list of conditions and the following disclaimer in the |
| 12 |
* documentation and/or other materials provided with the distribution. |
| 13 |
* |
| 14 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 15 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 18 |
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 19 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 20 |
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 21 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 22 |
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 23 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 24 |
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 |
*/ |
| 26 |
|
| 27 |
/***************************************************************************** |
| 28 |
DBTests.h |
| 29 |
|
| 30 |
Contains lowest level test cases for the database backend implementation. |
| 31 |
*****************************************************************************/ |
| 32 |
|
| 33 |
#ifndef _SOFTHSM_V2_DBTESTS_H |
| 34 |
#define _SOFTHSM_V2_DBTESTS_H |
| 35 |
|
| 36 |
#include <cppunit/extensions/HelperMacros.h> |
| 37 |
#include "DB.h" |
| 38 |
|
| 39 |
class test_a_db : public CppUnit::TestFixture |
| 40 |
{ |
| 41 |
CPPUNIT_TEST_SUITE(test_a_db); |
| 42 |
CPPUNIT_TEST(checks_for_empty_connection_parameters); |
| 43 |
CPPUNIT_TEST(can_be_connected_to_database); |
| 44 |
CPPUNIT_TEST_SUITE_END(); |
| 45 |
|
| 46 |
public: |
| 47 |
void checks_for_empty_connection_parameters(); |
| 48 |
void can_be_connected_to_database(); |
| 49 |
|
| 50 |
void setUp(); |
| 51 |
void tearDown(); |
| 52 |
|
| 53 |
protected: |
| 54 |
DB::Connection *null; |
| 55 |
|
| 56 |
private: |
| 57 |
}; |
| 58 |
|
| 59 |
class test_a_db_with_a_connection : public test_a_db |
| 60 |
{ |
| 61 |
CPPUNIT_TEST_SUITE(test_a_db_with_a_connection); |
| 62 |
CPPUNIT_TEST(can_prepare_statements); |
| 63 |
CPPUNIT_TEST(can_perform_statements); |
| 64 |
CPPUNIT_TEST(maintains_correct_refcounts); |
| 65 |
CPPUNIT_TEST(can_create_tables); |
| 66 |
CPPUNIT_TEST_SUITE_END(); |
| 67 |
public: |
| 68 |
void setUp(); |
| 69 |
void tearDown(); |
| 70 |
|
| 71 |
void can_prepare_statements(); |
| 72 |
void can_perform_statements(); |
| 73 |
void maintains_correct_refcounts(); |
| 74 |
void can_create_tables(); |
| 75 |
protected: |
| 76 |
DB::Connection *connection; |
| 77 |
|
| 78 |
private: |
| 79 |
}; |
| 80 |
|
| 81 |
class test_a_db_with_a_connection_with_tables : public test_a_db_with_a_connection |
| 82 |
{ |
| 83 |
CPPUNIT_TEST_SUITE(test_a_db_with_a_connection_with_tables); |
| 84 |
CPPUNIT_TEST(can_insert_records); |
| 85 |
CPPUNIT_TEST(can_retrieve_records); |
| 86 |
CPPUNIT_TEST(can_cascade_delete_objects_and_attributes); |
| 87 |
CPPUNIT_TEST(can_update_text_attribute); |
| 88 |
CPPUNIT_TEST(can_update_text_attribute_bound_value); |
| 89 |
CPPUNIT_TEST(can_update_integer_attribute_bound_value); |
| 90 |
CPPUNIT_TEST(can_update_blob_attribute_bound_value); |
| 91 |
CPPUNIT_TEST(will_not_insert_non_existing_attribute_on_update); |
| 92 |
CPPUNIT_TEST(can_update_boolean_attribute_bound_value); |
| 93 |
CPPUNIT_TEST(can_update_real_attribute_bound_value); |
| 94 |
CPPUNIT_TEST(supports_transactions); |
| 95 |
CPPUNIT_TEST_SUITE_END(); |
| 96 |
public: |
| 97 |
void setUp(); |
| 98 |
void tearDown(); |
| 99 |
|
| 100 |
void can_insert_records(); |
| 101 |
void can_retrieve_records(); |
| 102 |
void can_cascade_delete_objects_and_attributes(); |
| 103 |
void can_update_text_attribute(); |
| 104 |
void can_update_text_attribute_bound_value(); |
| 105 |
void can_update_integer_attribute_bound_value(); |
| 106 |
void can_update_blob_attribute_bound_value(); |
| 107 |
void will_not_insert_non_existing_attribute_on_update(); |
| 108 |
void can_update_boolean_attribute_bound_value(); |
| 109 |
void can_update_real_attribute_bound_value(); |
| 110 |
void supports_transactions(); |
| 111 |
protected: |
| 112 |
|
| 113 |
private: |
| 114 |
}; |
| 115 |
|
| 116 |
class test_a_db_with_a_connection_with_tables_with_a_second_connection_open : public test_a_db_with_a_connection_with_tables |
| 117 |
{ |
| 118 |
CPPUNIT_TEST_SUITE(test_a_db_with_a_connection_with_tables_with_a_second_connection_open); |
| 119 |
CPPUNIT_TEST(handles_nested_transactions); |
| 120 |
CPPUNIT_TEST(supports_transactions_with_other_connections_open); |
| 121 |
CPPUNIT_TEST_SUITE_END(); |
| 122 |
public: |
| 123 |
void setUp(); |
| 124 |
void tearDown(); |
| 125 |
|
| 126 |
void handles_nested_transactions(); |
| 127 |
void supports_transactions_with_other_connections_open(); |
| 128 |
protected: |
| 129 |
DB::Connection *connection2; |
| 130 |
|
| 131 |
private: |
| 132 |
}; |
| 133 |
|
| 134 |
#endif // !_SOFTHSM_V2_DBTESTS_H |