PageRenderTime 45ms CodeModel.GetById 28ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/test/lltranscode_tut.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 89 lines | 50 code | 12 blank | 27 comment | 0 complexity | f29a1f3a9878dab0f9b9d7e9e58ec3e6 MD5 | raw file
 1/** 
 2 * @file llscriptresource_tut.cpp
 3 * @brief Test LLScriptResource
 4 *
 5 * $LicenseInfo:firstyear=2008&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26
27//#include <tut/tut.h>
28#include "linden_common.h"
29
30#include "lltut.h"
31
32#include "../newsim/lltranscode.cpp" // include TU to pull in newsim implementation.
33
34static const char test_utf8[] = "Edelwei\xc3\x9f";
35static const char test_utf7[] = "Edelwei+AN8-";
36static const char test_latin1[] = "Edelwei\xdf";
37static const char test_latin2[] = "Edelwei\xdf";
38
39namespace tut
40{
41	class LLTranscodeTestData
42	{
43	};
44	
45	typedef test_group<LLTranscodeTestData> LLTranscodeTestGroup;
46	typedef LLTranscodeTestGroup::object LLTranscodeTestObject;
47	LLTranscodeTestGroup transcodeTestGroup("transcode");
48
49	template<> template<>
50	void LLTranscodeTestObject::test<1>()
51	{
52#if LL_WINDOWS
53		skip("Windows APR libs can't transcode.");
54#endif
55		// Test utf8
56		std::stringstream input;
57		std::stringstream output;
58
59		input.str(test_utf7);
60		output.clear();
61		LLTranscode::transcode("charset=UTF-7", input, output);
62		ensure_equals("UTF-7 to UTF-8 transcoding", output.str(),
63						  std::string(test_utf8));
64
65		input.str(test_latin1);
66		output.clear();
67		LLTranscode::transcode("", input, output);
68		ensure_equals("Default (latin_1) to UTF8 transcoding", output.str(),
69			std::string(test_utf8));
70		
71		input.str(test_latin1);
72		output.clear();
73		LLTranscode::transcode("charset=iso-8859-1", input, output);
74		ensure_equals("latin_1 (ISO-8859-1) to UTF8 transcoding", output.str(),
75			std::string(test_utf8));
76	
77		input.str(test_latin2);
78		output.clear();
79		LLTranscode::transcode("charset=iso-8859-2", input, output);
80		ensure_equals("latin_2 (ISO-8859-2) to UTF8 transcoding", output.str(),
81			std::string(test_utf8));
82		
83		input.str(test_utf8);
84		output.clear();
85		LLTranscode::transcode("charset=utf-8", input, output);
86		ensure_equals("UTF8 to UTF8 transcoding", output.str(),
87			std::string(test_utf8));
88	}
89}