apicompatanamdw/bcdrivers/os/ossrv/glib/tests/markup-escape-test.c
changeset 2 0cb2248d0edc
child 8 d8ef7a232001
equal deleted inserted replaced
1:61e9400fe245 2:0cb2248d0edc
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #undef G_DISABLE_ASSERT
       
    18 #undef G_LOG_DOMAIN
       
    19 
       
    20 #include <stdarg.h>
       
    21 #include <string.h>
       
    22 #include <glib.h>
       
    23 #include <stdio.h>
       
    24 
       
    25 #ifdef SYMBIAN
       
    26 #include "mrt2_glib2_test.h"
       
    27 #endif /*SYMBIAN*/
       
    28 
       
    29 
       
    30 static void test_format (const gchar *format,
       
    31 			 const gchar *expected, ...) G_GNUC_PRINTF (1, 3);
       
    32 
       
    33 static gboolean error = FALSE;
       
    34 
       
    35 static void
       
    36 test (const gchar *original,
       
    37       const gchar *expected)
       
    38 {
       
    39   gchar *result = g_markup_escape_text (original, -1);
       
    40 
       
    41   if (strcmp (result, expected) != 0)
       
    42     {
       
    43       g_print ("g_markup_escape_text(): expected '%s', got '%s'\n",
       
    44 		  expected, result);
       
    45       error = TRUE;
       
    46       assert_failed = TRUE;
       
    47     }
       
    48 
       
    49   g_free (result);
       
    50 }
       
    51 
       
    52 static void
       
    53 test_format (const gchar *format,
       
    54 	     const gchar *expected,
       
    55 	     ...)
       
    56 {
       
    57   gchar *result;
       
    58   
       
    59   va_list args;
       
    60   
       
    61   va_start (args, expected);
       
    62   result = g_markup_vprintf_escaped (format, args);
       
    63   va_end (args);
       
    64 
       
    65   if (strcmp (result, expected) != 0)
       
    66     {
       
    67       g_print ("g_markup_printf_escaped(): expected '%s', got '%s'\n",
       
    68 		  expected, result);
       
    69 	  assert_failed = TRUE;
       
    70       error = TRUE;
       
    71     }
       
    72 
       
    73   g_free (result);
       
    74 }
       
    75 
       
    76 int main (int argc, char **argv)
       
    77 {
       
    78   #ifdef SYMBIAN
       
    79   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);
       
    80   g_set_print_handler(mrtPrintHandler);
       
    81   #endif /*SYMBIAN*/
       
    82 	  
       
    83 
       
    84   /* Tests for g_markup_escape_text() */
       
    85   test ("&", "&amp;");
       
    86   test ("<", "&lt;");
       
    87   test (">", "&gt;");
       
    88   test ("'", "&apos;");
       
    89   test ("\"", "&quot;");
       
    90   
       
    91   test ("", "");
       
    92   test ("A", "A");
       
    93   test ("A&", "A&amp;");
       
    94   test ("&A", "&amp;A");
       
    95   test ("A&A", "A&amp;A");
       
    96   test ("&&A", "&amp;&amp;A");
       
    97   test ("A&&", "A&amp;&amp;");
       
    98   test ("A&&A", "A&amp;&amp;A");
       
    99   test ("A&A&A", "A&amp;A&amp;A");
       
   100   
       
   101   /* Tests for g_markup_printf_escaped() */
       
   102   test_format ("A", "A");
       
   103   test_format ("A%s", "A&amp;", "&");
       
   104   test_format ("%sA", "&amp;A", "&");
       
   105   test_format ("A%sA", "A&amp;A", "&");
       
   106   test_format ("%s%sA", "&amp;&amp;A", "&", "&");
       
   107   test_format ("A%s%s", "A&amp;&amp;", "&", "&");
       
   108   test_format ("A%s%sA", "A&amp;&amp;A", "&", "&");
       
   109   test_format ("A%sA%sA", "A&amp;A&amp;A", "&", "&");
       
   110   
       
   111   test_format ("%s", "&lt;B&gt;&amp;",
       
   112 	       "<B>&");
       
   113   test_format ("%c%c", "&lt;&amp;",
       
   114 	       '<', '&');
       
   115   test_format (".%c.%c.", ".&lt;.&amp;.",
       
   116 	       '<', '&');
       
   117   test_format ("%s", "",
       
   118 	       "");
       
   119   test_format ("%-5s", "A    ",
       
   120 	       "A");
       
   121   test_format ("%2$s%1$s", "B.A.",
       
   122 	       "A.", "B.");
       
   123 	       
       
   124 
       
   125   #ifdef SYMBIAN
       
   126   testResultXml("markup-escape-test");
       
   127   #endif /* EMULATOR */
       
   128 
       
   129   return error ? 1 : 0;
       
   130 }