1 /*****************************************************************************/
2 // OpenBeOS Translation Kit Test
3 // Author: Michael Wilber
6 // This is the Test application for BTranslator
9 // This application and all source files used in its construction, except
10 // where noted, are licensed under the MIT License, and have been written
13 // Copyright (c) 2002 OpenBeOS Project
15 // Permission is hereby granted, free of charge, to any person obtaining a
16 // copy of this software and associated documentation files (the "Software"),
17 // to deal in the Software without restriction, including without limitation
18 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
19 // and/or sell copies of the Software, and to permit persons to whom the
20 // Software is furnished to do so, subject to the following conditions:
22 // The above copyright notice and this permission notice shall be included
23 // in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
26 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31 // DEALINGS IN THE SOFTWARE.
32 /*****************************************************************************/
33 #include "TranslatorTest.h"
34 #include <TranslatorRoster.h>
35 #include <Application.h>
39 /* cppunit framework */
40 #include <cppunit/Test.h>
41 #include <cppunit/TestCaller.h>
42 #include <cppunit/TestSuite.h>
44 // BTranslator derived class to test with
45 class BTranslatorTester
: public BTranslator
{
49 virtual const char *TranslatorName() const { return "NoName"; };
50 virtual const char *TranslatorInfo() const { return "NoInfo"; };
51 virtual int32
TranslatorVersion() const { return 100; };
53 virtual const translation_format
*InputFormats(int32
*out_count
) const;
54 virtual const translation_format
*OutputFormats(int32
*out_count
) const;
56 virtual status_t
Identify(BPositionIO
*inSource
,
57 const translation_format
*inFormat
, BMessage
*ioExtension
,
58 translator_info
*outInfo
, uint32 outType
) { return B_ERROR
; };
60 virtual status_t
Translate(BPositionIO
*inSource
,
61 const translator_info
*inInfo
, BMessage
*ioExtension
,
62 uint32 outType
, BPositionIO
*outDestination
) { return B_ERROR
; };
65 BTranslatorTester::BTranslatorTester()
70 const translation_format
*
71 BTranslatorTester::InputFormats(int32
*out_count
) const
73 if (out_count
) *out_count
= 0;
77 const translation_format
*
78 BTranslatorTester::OutputFormats(int32
*out_count
) const
80 if (out_count
) *out_count
= 0;
85 * Default constructor - no work
87 TranslatorTest::TranslatorTest(std::string name
)
93 * Default destructor - no work
95 TranslatorTest::~TranslatorTest()
100 TranslatorTest::Suite()
102 /* create our suite */
103 CppUnit::TestSuite
*suite
= new CppUnit::TestSuite("Translator");
106 suite
->addTest(new CppUnit::TestCaller
<TranslatorTest
>("TranslatorTest::AcquireRelease Test", &TranslatorTest::AcquireReleaseTest
));
107 suite
->addTest(new CppUnit::TestCaller
<TranslatorTest
>("TranslatorTest::MakeConfigurationView Test", &TranslatorTest::MakeConfigurationViewTest
));
108 suite
->addTest(new CppUnit::TestCaller
<TranslatorTest
>("TranslatorTest::GetConfigurationMessage Test", &TranslatorTest::GetConfigurationMessageTest
));
114 TranslatorTest::AcquireReleaseTest()
116 // Create new BTranslator
118 BTranslatorTester
*ptt
= new BTranslatorTester();
120 BTranslator
*ptranslator
= static_cast<BTranslator
*>(ptt
);
121 CPPUNIT_ASSERT(ptranslator
);
122 CPPUNIT_ASSERT(ptranslator
->ReferenceCount() == 1);
124 // Do some Acquire()ing
126 BTranslator
*pcomptran
;
127 pcomptran
= ptranslator
->Acquire();
128 CPPUNIT_ASSERT(pcomptran
== ptranslator
);
129 CPPUNIT_ASSERT(ptranslator
->ReferenceCount() == 2);
133 CPPUNIT_ASSERT(ptranslator
->Release() == ptranslator
);
134 CPPUNIT_ASSERT(ptranslator
->ReferenceCount() == 1);
138 CPPUNIT_ASSERT(ptranslator
->Release() == NULL
);
145 TranslatorTest::MakeConfigurationViewTest()
147 // Create new BTranslator
150 "application/x-vnd.OpenBeOS-translationkit_translatortest");
151 BTranslatorTester
*ptt
= new BTranslatorTester();
153 BTranslator
*ptranslator
= static_cast<BTranslator
*>(ptt
);
154 CPPUNIT_ASSERT(ptranslator
);
155 CPPUNIT_ASSERT(ptranslator
->ReferenceCount() == 1);
157 // Try GetConfigurationMessage
162 CPPUNIT_ASSERT(ptranslator
->MakeConfigurationView(NULL
,
163 NULL
, NULL
) == B_ERROR
);
164 CPPUNIT_ASSERT(ptranslator
->MakeConfigurationView(&bmsg
,
165 &pview
, &rect
) == B_ERROR
);
166 CPPUNIT_ASSERT(bmsg
.IsEmpty() == true);
170 CPPUNIT_ASSERT(ptranslator
->Release() == NULL
);
176 TranslatorTest::GetConfigurationMessageTest()
178 // Create new BTranslator
180 BTranslatorTester
*ptt
= new BTranslatorTester();
182 BTranslator
*ptranslator
= static_cast<BTranslator
*>(ptt
);
183 CPPUNIT_ASSERT(ptranslator
);
184 CPPUNIT_ASSERT(ptranslator
->ReferenceCount() == 1);
186 // Try GetConfigurationMessage
189 CPPUNIT_ASSERT(ptranslator
->GetConfigurationMessage(NULL
) == B_ERROR
);
190 CPPUNIT_ASSERT(ptranslator
->GetConfigurationMessage(&bmsg
) == B_ERROR
);
191 CPPUNIT_ASSERT(bmsg
.IsEmpty() == true);
195 CPPUNIT_ASSERT(ptranslator
->Release() == NULL
);