File: test_data_adaptor.ts.cpp

package info (click to toggle)
diagnostics 0.3.1-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,032 kB
  • ctags: 2,008
  • sloc: cpp: 13,596; sh: 9,706; makefile: 273; ansic: 9
file content (114 lines) | stat: -rw-r--r-- 3,511 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * Diagnostics - a unified framework for code annotation, logging,
 * program monitoring, and unit-testing.
 *
 * Copyright (C) 2009 Christian Schallhart <christian@schallhart.net>,
 *                    Michael Tautschnig <tautschnig@forsyte.de>
 *               2008 model.in.tum.de group, FORSYTE group
 *               2006-2007 model.in.tum.de group
 *               2002-2005 Christian Schallhart
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */


/**
 * @file diagnostics/unittest/test_system/test_data_adaptor.ts.cpp
 *
 * @brief [LEVEL: beta] Implementation of the compliance test for
 * @ref diagnostics::unittest::Test_Data_Adaptor
 *
 * $Id: test_data_adaptor.ts.cpp,v 1.11 2005/06/23 09:54:26 esdentem Exp $
 * 
 * @author Christian Schallhart
 */

#include <diagnostics/unittest/test_system/test_data_adaptor.ts.hpp>

// used components
#include <diagnostics/unittest/test_system/test_data_adaptor.hpp>
#include <diagnostics/unittest/test_system_exception.hpp>

// test support
#include <diagnostics/util/dummy_test_data_source.ts.hpp>


DIAGNOSTICS_NAMESPACE_BEGIN;
UNITTEST_NAMESPACE_BEGIN;
TEST_NAMESPACE_BEGIN;

Test_Data_Adaptor_Compliance::Test_Data_Adaptor_Compliance(Test_Data_Adaptor * const adaptor)
    : m_adaptor(adaptor)
{
}


Test_Data_Adaptor_Compliance::Test_Data_Adaptor_Compliance(Self const & other)
    : m_adaptor(other.m_adaptor)
{
}

Test_Data_Adaptor_Compliance & Test_Data_Adaptor_Compliance::operator=(Self const & other)
{
    m_adaptor=other.m_adaptor;
    return *this;
}


void Test_Data_Adaptor_Compliance::operator()(Test_Data & test_data) const
{
    Dummy_Test_Data_Source source;
    
    // copy for later comparision
    Dummy_Test_Data_Source::Data_t const data(source.data());

    // backend()==NULL after construction
    TEST_ASSERT(m_adaptor->backend()==NULL);

    // get() throws if backend()==NULL
    TEST_THROWING_BLOCK_ENTER;
    m_adaptor->get("1");
    TEST_THROWING_BLOCK_EXIT(Test_System_Exception);
    
    // attach(NULL) throws and does not change backend()
    TEST_THROWING_BLOCK_ENTER;
    m_adaptor->attach(NULL);
    TEST_THROWING_BLOCK_EXIT(Test_System_Exception);
    TEST_ASSERT(m_adaptor->backend()==NULL);
    
    // attach(&source) --> backend()==&source and get does not throw
    m_adaptor->attach(&source);
    TEST_ASSERT(m_adaptor->backend()==&source);

    // attach(NULL) throws and does not change backend()
    TEST_THROWING_BLOCK_ENTER;
    m_adaptor->attach(NULL);
    TEST_THROWING_BLOCK_EXIT(Test_System_Exception);
    TEST_ASSERT(m_adaptor->backend()==&source);


    // we can access the 1
    TEST_ASSERT(m_adaptor->get("1")=="A");

    // compare data of Test_Data_Source
    TEST_ASSERT(data==source.data());
}



TEST_NAMESPACE_END;
UNITTEST_NAMESPACE_END;
DIAGNOSTICS_NAMESPACE_END;
// vim:ts=4:sw=4