diff -r 61e9400fe245 -r 0cb2248d0edc apicompatanamdw/bcdrivers/os/ossrv/glib/tests/markup-escape-test.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/apicompatanamdw/bcdrivers/os/ossrv/glib/tests/markup-escape-test.c Thu Apr 22 17:15:08 2010 +0530 @@ -0,0 +1,130 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +#undef G_DISABLE_ASSERT +#undef G_LOG_DOMAIN + +#include +#include +#include +#include + +#ifdef SYMBIAN +#include "mrt2_glib2_test.h" +#endif /*SYMBIAN*/ + + +static void test_format (const gchar *format, + const gchar *expected, ...) G_GNUC_PRINTF (1, 3); + +static gboolean error = FALSE; + +static void +test (const gchar *original, + const gchar *expected) +{ + gchar *result = g_markup_escape_text (original, -1); + + if (strcmp (result, expected) != 0) + { + g_print ("g_markup_escape_text(): expected '%s', got '%s'\n", + expected, result); + error = TRUE; + assert_failed = TRUE; + } + + g_free (result); +} + +static void +test_format (const gchar *format, + const gchar *expected, + ...) +{ + gchar *result; + + va_list args; + + va_start (args, expected); + result = g_markup_vprintf_escaped (format, args); + va_end (args); + + if (strcmp (result, expected) != 0) + { + g_print ("g_markup_printf_escaped(): expected '%s', got '%s'\n", + expected, result); + assert_failed = TRUE; + error = TRUE; + } + + g_free (result); +} + +int main (int argc, char **argv) +{ + #ifdef SYMBIAN + g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL); + g_set_print_handler(mrtPrintHandler); + #endif /*SYMBIAN*/ + + + /* Tests for g_markup_escape_text() */ + test ("&", "&"); + test ("<", "<"); + test (">", ">"); + test ("'", "'"); + test ("\"", """); + + test ("", ""); + test ("A", "A"); + test ("A&", "A&"); + test ("&A", "&A"); + test ("A&A", "A&A"); + test ("&&A", "&&A"); + test ("A&&", "A&&"); + test ("A&&A", "A&&A"); + test ("A&A&A", "A&A&A"); + + /* Tests for g_markup_printf_escaped() */ + test_format ("A", "A"); + test_format ("A%s", "A&", "&"); + test_format ("%sA", "&A", "&"); + test_format ("A%sA", "A&A", "&"); + test_format ("%s%sA", "&&A", "&", "&"); + test_format ("A%s%s", "A&&", "&", "&"); + test_format ("A%s%sA", "A&&A", "&", "&"); + test_format ("A%sA%sA", "A&A&A", "&", "&"); + + test_format ("%s", "<B>&", + "&"); + test_format ("%c%c", "<&", + '<', '&'); + test_format (".%c.%c.", ".<.&.", + '<', '&'); + test_format ("%s", "", + ""); + test_format ("%-5s", "A ", + "A"); + test_format ("%2$s%1$s", "B.A.", + "A.", "B."); + + + #ifdef SYMBIAN + testResultXml("markup-escape-test"); + #endif /* EMULATOR */ + + return error ? 1 : 0; +}