summaryrefslogtreecommitdiffstats
path: root/qa/libcmis-c/test-property.cxx
blob: 99c9b2cf51ef2901d94b9ced9cb3c3dbc4ef22d4 (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/* libcmis
 * Version: MPL 1.1 / GPLv2+ / LGPLv2+
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License or as specified alternatively below. You may obtain a copy of
 * the License at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * Major Contributor(s):
 * Copyright (C) 2011 SUSE <cbosdonnat@suse.com>
 *
 *
 * All Rights Reserved.
 *
 * For minor contributions see the git repository.
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
 * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
 * instead of those above.
 */

#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
#include <cppunit/TestAssert.h>

#include <libcmis-c/property.h>
#include <libcmis-c/property-type.h>
#include <libcmis-c/vectors.h>

#include "internals.hxx"
#include "test-dummies.hxx"

using namespace std;

class PropertyTest : public CppUnit::TestFixture
{
    private:
        libcmis_PropertyTypePtr getTestType( string xmlType );

    public:
        void getDateTimesTest( );
        void getBoolsTest( );
        void getStringsTest( );
        void getLongsTest( );
        void getDoublesTest( );
        void setValuesTest( );

        CPPUNIT_TEST_SUITE( PropertyTest );
        CPPUNIT_TEST( getDateTimesTest );
        CPPUNIT_TEST( getBoolsTest );
        CPPUNIT_TEST( getStringsTest );
        CPPUNIT_TEST( getLongsTest );
        CPPUNIT_TEST( getDoublesTest );
        CPPUNIT_TEST( setValuesTest );
        CPPUNIT_TEST_SUITE_END( );
};

CPPUNIT_TEST_SUITE_REGISTRATION( PropertyTest );

libcmis_PropertyTypePtr PropertyTest::getTestType( string xmlType )
{
    libcmis_PropertyTypePtr result = new libcmis_property_type( );
    libcmis::PropertyTypePtr handle( new dummies::PropertyType( "Id", xmlType ) );
    result->handle = handle;

    return result;
}

void PropertyTest::getDateTimesTest( )
{
    libcmis_PropertyTypePtr type = getTestType( "datetime" );
    size_t size = 2;
    const char** values = new const char*[size];
    values[0] = "2012-01-19T09:06:57.388Z";
    values[1] = "2012-02-19T09:06:57.388Z";
    libcmis_PropertyPtr tested  = libcmis_property_create( type, values, size );

    libcmis_vector_time_Ptr times = libcmis_property_getDateTimes( tested );
    CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_time_size( times ) ); 
    libcmis_vector_time_free( times );

    libcmis_vector_string_Ptr strings = libcmis_property_getStrings( tested );
    CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_string_size( strings ) );
    CPPUNIT_ASSERT_EQUAL( string( values[1] ), string( libcmis_vector_string_get( strings, 1 ) ) );
    libcmis_vector_string_free( strings );
    delete[] values;

    libcmis_vector_bool_Ptr bools = libcmis_property_getBools( tested );
    CPPUNIT_ASSERT_EQUAL( size_t( 0 ), libcmis_vector_bool_size( bools ) );
    libcmis_vector_bool_free( bools );

    libcmis_property_free( tested );
    libcmis_property_type_free( type );
}

void PropertyTest::getBoolsTest( )
{
    libcmis_PropertyTypePtr type = getTestType( "boolean" );
    size_t size = 2;
    const char** values = new const char*[size];
    values[0] = "true";
    values[1] = "false";
    libcmis_PropertyPtr tested  = libcmis_property_create( type, values, size );

    libcmis_vector_bool_Ptr bools = libcmis_property_getBools( tested );
    CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_bool_size( bools ) );
    CPPUNIT_ASSERT_EQUAL( true, libcmis_vector_bool_get( bools, 0 ) );
    CPPUNIT_ASSERT_EQUAL( false, libcmis_vector_bool_get( bools, 1 ) );
    libcmis_vector_bool_free( bools );

    libcmis_vector_string_Ptr strings = libcmis_property_getStrings( tested );
    CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_string_size( strings ) );
    CPPUNIT_ASSERT_EQUAL( string( values[1] ), string( libcmis_vector_string_get( strings, 1 ) ) );
    libcmis_vector_string_free( strings );
    delete[] values;

    libcmis_vector_long_Ptr longs = libcmis_property_getLongs( tested );
    CPPUNIT_ASSERT_EQUAL( size_t( 0 ), libcmis_vector_long_size( longs ) );
    libcmis_vector_long_free( longs );

    libcmis_property_free( tested );
    libcmis_property_type_free( type );
}


void PropertyTest::getStringsTest( )
{
    libcmis_PropertyTypePtr type = getTestType( "string" );
    size_t size = 2;
    const char** values = new const char*[size];
    values[0] = "string 1";
    values[1] = "string 2";
    libcmis_PropertyPtr tested  = libcmis_property_create( type, values, size );

    libcmis_vector_string_Ptr strings = libcmis_property_getStrings( tested );
    CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_string_size( strings ) );
    CPPUNIT_ASSERT_EQUAL( string( values[0] ), string( libcmis_vector_string_get( strings, 0 ) ) );
    CPPUNIT_ASSERT_EQUAL( string( values[1] ), string( libcmis_vector_string_get( strings, 1 ) ) );
    libcmis_vector_string_free( strings );
    delete[] values;

    libcmis_vector_double_Ptr doubles = libcmis_property_getDoubles( tested );
    CPPUNIT_ASSERT_EQUAL( size_t( 0 ), libcmis_vector_double_size( doubles ) );
    libcmis_vector_double_free( doubles );

    libcmis_property_free( tested );
    libcmis_property_type_free( type );
}


void PropertyTest::getLongsTest( )
{
    libcmis_PropertyTypePtr type = getTestType( "integer" );
    size_t size = 2;
    const char** values = new const char*[size];
    values[0] = "123456";
    values[1] = "789";
    libcmis_PropertyPtr tested  = libcmis_property_create( type, values, size );

    libcmis_vector_long_Ptr longs = libcmis_property_getLongs( tested );
    CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_long_size( longs ) );
    CPPUNIT_ASSERT_EQUAL( long( 123456 ), libcmis_vector_long_get( longs, 0 ) );
    CPPUNIT_ASSERT_EQUAL( long( 789 ), libcmis_vector_long_get( longs, 1 ) );
    libcmis_vector_long_free( longs );

    libcmis_vector_string_Ptr strings = libcmis_property_getStrings( tested );
    CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_string_size( strings ) );
    CPPUNIT_ASSERT_EQUAL( string( values[1] ), string( libcmis_vector_string_get( strings, 1 ) ) );
    libcmis_vector_string_free( strings );
    delete[] values;

    libcmis_vector_time_Ptr times = libcmis_property_getDateTimes( tested );
    CPPUNIT_ASSERT_EQUAL( size_t( 0 ), libcmis_vector_time_size( times ) );
    libcmis_vector_time_free( times );

    libcmis_property_free( tested );
    libcmis_property_type_free( type );
}


void PropertyTest::getDoublesTest( )
{
    libcmis_PropertyTypePtr type = getTestType( "decimal" );
    size_t size = 2;
    const char** values = new const char*[size];
    values[0] = "123.456";
    values[1] = "7.89";
    libcmis_PropertyPtr tested  = libcmis_property_create( type, values, size );

    libcmis_vector_double_Ptr doubles = libcmis_property_getDoubles( tested );
    CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_double_size( doubles ) );
    CPPUNIT_ASSERT_EQUAL( 123.456, libcmis_vector_double_get( doubles, 0 ) );
    CPPUNIT_ASSERT_EQUAL( 7.89, libcmis_vector_double_get( doubles, 1 ) );
    libcmis_vector_double_free( doubles );

    libcmis_vector_string_Ptr strings = libcmis_property_getStrings( tested );
    CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_string_size( strings ) );
    CPPUNIT_ASSERT_EQUAL( string( values[1] ), string( libcmis_vector_string_get( strings, 1 ) ) );
    libcmis_vector_string_free( strings );
    delete[] values;

    libcmis_vector_long_Ptr longs = libcmis_property_getLongs( tested );
    CPPUNIT_ASSERT_EQUAL( size_t( 0 ), libcmis_vector_long_size( longs ) );
    libcmis_vector_long_free( longs );

    libcmis_property_free( tested );
    libcmis_property_type_free( type );
}


void PropertyTest::setValuesTest( )
{
    libcmis_PropertyTypePtr type = getTestType( "string" );
    size_t size = 1;
    const char** values = new const char*[size];
    values[0] = "string 1";
    libcmis_PropertyPtr tested  = libcmis_property_create( type, values, size );
    delete[] values;

    size_t newSize = 2;
    const char** newValues = new const char*[newSize];
    newValues[0] = "new string 1";
    newValues[1] = "new string 2";
    libcmis_property_setValues( tested, newValues, newSize );

    libcmis_vector_string_Ptr newStrings = libcmis_property_getStrings( tested );
    CPPUNIT_ASSERT_EQUAL( newSize, libcmis_vector_string_size( newStrings ) );
    CPPUNIT_ASSERT_EQUAL( string( newValues[0] ), string( libcmis_vector_string_get( newStrings, 0 ) ) );
    CPPUNIT_ASSERT_EQUAL( string( newValues[1] ), string( libcmis_vector_string_get( newStrings, 1 ) ) );
    libcmis_vector_string_free( newStrings );
    delete[] newValues;

    libcmis_property_free( tested );
    libcmis_property_type_free( type );
}