1 /* libcmis
2  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License or as specified alternatively below. You may obtain a copy of
7  * the License at http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * Major Contributor(s):
15  * Copyright (C) 2011 SUSE <cbosdonnat@suse.com>
16  *
17  *
18  * All Rights Reserved.
19  *
20  * For minor contributions see the git repository.
21  *
22  * Alternatively, the contents of this file may be used under the terms of
23  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
24  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
25  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
26  * instead of those above.
27  */
28 
29 #include <cppunit/extensions/HelperMacros.h>
30 #include <cppunit/TestFixture.h>
31 #include <cppunit/TestAssert.h>
32 
33 #include <libcmis-c/property-type.h>
34 
35 #include "internals.hxx"
36 #include "test-dummies.hxx"
37 
38 using namespace std;
39 
40 class PropertyTypeTest : public CppUnit::TestFixture
41 {
42     private:
43         libcmis_PropertyTypePtr getTested( string id, string xmlType );
44 
45     public:
46         void getIdTest( );
47         void getLocalNameTest( );
48         void getLocalNamespaceTest( );
49         void getDisplayNameTest( );
50         void getQueryNameTest( );
51         void getTypeTest( );
52         void isMultiValuedTest( );
53         void isUpdatableTest( );
54         void isInheritedTest( );
55         void isRequiredTest( );
56         void isQueryableTest( );
57         void isOrderableTest( );
58         void isOpenChoiceTest( );
59 
60         CPPUNIT_TEST_SUITE( PropertyTypeTest );
61         CPPUNIT_TEST( getIdTest );
62         CPPUNIT_TEST( getLocalNameTest );
63         CPPUNIT_TEST( getLocalNamespaceTest );
64         CPPUNIT_TEST( getDisplayNameTest );
65         CPPUNIT_TEST( getQueryNameTest );
66         CPPUNIT_TEST( getTypeTest );
67         CPPUNIT_TEST( isMultiValuedTest );
68         CPPUNIT_TEST( isUpdatableTest );
69         CPPUNIT_TEST( isInheritedTest );
70         CPPUNIT_TEST( isRequiredTest );
71         CPPUNIT_TEST( isQueryableTest );
72         CPPUNIT_TEST( isOrderableTest );
73         CPPUNIT_TEST( isOpenChoiceTest );
74         CPPUNIT_TEST_SUITE_END( );
75 };
76 
77 CPPUNIT_TEST_SUITE_REGISTRATION( PropertyTypeTest );
78 
getTested(string id,string xmlType)79 libcmis_PropertyTypePtr PropertyTypeTest::getTested( string id, string xmlType )
80 {
81     libcmis_PropertyTypePtr result = new libcmis_property_type( );
82     libcmis::PropertyTypePtr handle( new dummies::PropertyType( id, xmlType ) );
83     result->handle = handle;
84 
85     return result;
86 }
87 
getIdTest()88 void PropertyTypeTest::getIdTest( )
89 {
90     string id( "Id" );
91     libcmis_PropertyTypePtr tested = getTested( id, "string" );
92     char* actual = libcmis_property_type_getId( tested );
93     CPPUNIT_ASSERT_EQUAL( id, string( actual ) );
94 
95     free( actual );
96     libcmis_property_type_free( tested );
97 }
98 
getLocalNameTest()99 void PropertyTypeTest::getLocalNameTest( )
100 {
101     libcmis_PropertyTypePtr tested = getTested( "id", "string" );
102     char* actual = libcmis_property_type_getLocalName( tested );
103     CPPUNIT_ASSERT_EQUAL( string( "PropertyType::LocalName" ), string( actual ) );
104 
105     free( actual );
106     libcmis_property_type_free( tested );
107 }
108 
getLocalNamespaceTest()109 void PropertyTypeTest::getLocalNamespaceTest( )
110 {
111     libcmis_PropertyTypePtr tested = getTested( "id", "string" );
112     char* actual = libcmis_property_type_getLocalNamespace( tested );
113     CPPUNIT_ASSERT_EQUAL( string( "PropertyType::LocalNamespace" ), string( actual ) );
114 
115     free( actual );
116     libcmis_property_type_free( tested );
117 }
118 
getDisplayNameTest()119 void PropertyTypeTest::getDisplayNameTest( )
120 {
121     libcmis_PropertyTypePtr tested = getTested( "id", "string" );
122     char* actual = libcmis_property_type_getDisplayName( tested );
123     CPPUNIT_ASSERT_EQUAL( string( "PropertyType::DisplayName" ), string( actual ) );
124 
125     free( actual );
126     libcmis_property_type_free( tested );
127 }
128 
getQueryNameTest()129 void PropertyTypeTest::getQueryNameTest( )
130 {
131     libcmis_PropertyTypePtr tested = getTested( "id", "string" );
132     char* actual = libcmis_property_type_getQueryName( tested );
133     CPPUNIT_ASSERT_EQUAL( string( "PropertyType::QueryName" ), string( actual ) );
134 
135     free( actual );
136     libcmis_property_type_free( tested );
137 }
138 
getTypeTest()139 void PropertyTypeTest::getTypeTest( )
140 {
141     // String
142     {
143         libcmis_PropertyTypePtr tested = getTested( "id", "string" );
144         libcmis_property_type_Type actualType = libcmis_property_type_getType( tested );
145         CPPUNIT_ASSERT_EQUAL( libcmis_String, actualType );
146         char* actualXml = libcmis_property_type_getXmlType( tested );
147         CPPUNIT_ASSERT_EQUAL( string( "String" ), string( actualXml ) );
148 
149         free( actualXml );
150         libcmis_property_type_free( tested );
151     }
152 
153     // DateTime
154     {
155         libcmis_PropertyTypePtr tested = getTested( "id", "datetime" );
156         libcmis_property_type_Type actualType = libcmis_property_type_getType( tested );
157         CPPUNIT_ASSERT_EQUAL( libcmis_DateTime, actualType );
158         char* actualXml = libcmis_property_type_getXmlType( tested );
159         CPPUNIT_ASSERT_EQUAL( string( "DateTime" ), string( actualXml ) );
160 
161         free( actualXml );
162         libcmis_property_type_free( tested );
163     }
164 
165     // Integer
166     {
167         libcmis_PropertyTypePtr tested = getTested( "id", "integer" );
168         libcmis_property_type_Type actualType = libcmis_property_type_getType( tested );
169         CPPUNIT_ASSERT_EQUAL( libcmis_Integer, actualType );
170         char* actualXml = libcmis_property_type_getXmlType( tested );
171         CPPUNIT_ASSERT_EQUAL( string( "Integer" ), string( actualXml ) );
172 
173         free( actualXml );
174         libcmis_property_type_free( tested );
175     }
176 
177     // Html
178     {
179         libcmis_PropertyTypePtr tested = getTested( "id", "html" );
180         libcmis_property_type_Type actualType = libcmis_property_type_getType( tested );
181         CPPUNIT_ASSERT_EQUAL( libcmis_String, actualType );
182         char* actualXml = libcmis_property_type_getXmlType( tested );
183         CPPUNIT_ASSERT_EQUAL( string( "Html" ), string( actualXml ) );
184 
185         free( actualXml );
186         libcmis_property_type_free( tested );
187     }
188 }
189 
isMultiValuedTest()190 void PropertyTypeTest::isMultiValuedTest( )
191 {
192     libcmis_PropertyTypePtr tested = getTested( "id", "string" );
193     bool actual = libcmis_property_type_isMultiValued( tested );
194     CPPUNIT_ASSERT_EQUAL( true , actual );
195 
196     libcmis_property_type_free( tested );
197 }
198 
isUpdatableTest()199 void PropertyTypeTest::isUpdatableTest( )
200 {
201     libcmis_PropertyTypePtr tested = getTested( "id", "string" );
202     bool actual = libcmis_property_type_isUpdatable( tested );
203     CPPUNIT_ASSERT_EQUAL( true , actual );
204 
205     libcmis_property_type_free( tested );
206 }
207 
isInheritedTest()208 void PropertyTypeTest::isInheritedTest( )
209 {
210     libcmis_PropertyTypePtr tested = getTested( "id", "string" );
211     bool actual = libcmis_property_type_isInherited( tested );
212     CPPUNIT_ASSERT_EQUAL( true , actual );
213 
214     libcmis_property_type_free( tested );
215 }
216 
isRequiredTest()217 void PropertyTypeTest::isRequiredTest( )
218 {
219     libcmis_PropertyTypePtr tested = getTested( "id", "string" );
220     bool actual = libcmis_property_type_isRequired( tested );
221     CPPUNIT_ASSERT_EQUAL( true , actual );
222 
223     libcmis_property_type_free( tested );
224 }
225 
isQueryableTest()226 void PropertyTypeTest::isQueryableTest( )
227 {
228     libcmis_PropertyTypePtr tested = getTested( "id", "string" );
229     bool actual = libcmis_property_type_isQueryable( tested );
230     CPPUNIT_ASSERT_EQUAL( true , actual );
231 
232     libcmis_property_type_free( tested );
233 }
234 
isOrderableTest()235 void PropertyTypeTest::isOrderableTest( )
236 {
237     libcmis_PropertyTypePtr tested = getTested( "id", "string" );
238     bool actual = libcmis_property_type_isOrderable( tested );
239     CPPUNIT_ASSERT_EQUAL( true , actual );
240 
241     libcmis_property_type_free( tested );
242 }
243 
isOpenChoiceTest()244 void PropertyTypeTest::isOpenChoiceTest( )
245 {
246     libcmis_PropertyTypePtr tested = getTested( "id", "string" );
247     bool actual = libcmis_property_type_isOpenChoice( tested );
248     CPPUNIT_ASSERT_EQUAL( true , actual );
249 
250     libcmis_property_type_free( tested );
251 }
252