1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
|
/* EasyTAG - tag editor for audio files
* Copyright (C) 2014 David King <amigadave@amigadave.com>
* Copyright (C) 2014 Abhinav Jangda <abhijangda@hotmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "scan.h"
/* TODO: Add more test strings. */
static const gsize PERF_ITERATIONS = 500000;
static void
check_string (const gchar *cases, const gchar *result)
{
gchar *string1, *string2;
string1 = g_utf8_normalize (cases, -1, G_NORMALIZE_ALL);
string2 = g_utf8_normalize (result, -1, G_NORMALIZE_ALL);
g_assert_cmpstr (string1, ==, string2);
g_free (string1);
g_free (string2);
}
static void
scan_underscore_to_space (void)
{
gsize i;
const gchar * const cases[] = { " ်0STRING ်0_A_B" };
const gchar * const results[] = { " ်0STRING ်0 A B" };
for (i = 0; i < G_N_ELEMENTS (cases); i++)
{
gchar *string;
string = g_strdup (cases[i]);
Scan_Convert_Underscore_Into_Space (string);
check_string (string, results[i]);
g_free (string);
}
}
static void
scan_remove_space (void)
{
gsize i;
const gchar * const cases[] = { " STR ING A B " };
const gchar * const results[] = { "STRINGAB" };
for (i = 0; i < G_N_ELEMENTS (cases); i++)
{
gchar *string;
string = g_strdup (cases[i]);
Scan_Process_Fields_Remove_Space (string);
check_string (string, results[i]);
g_free (string);
}
}
static void
scan_p20_to_space (void)
{
gsize i;
const gchar * const cases[] = { "S%20T%20R%20", "%20ă b %20c",
"STЂR%20ING%20A%20B" };
const gchar * const results[] = { "S T R ", " ă b c", "STЂR ING A B" };
for (i = 0; i < G_N_ELEMENTS (cases); i++)
{
gchar *string;
string = g_strdup (cases[i]);
Scan_Convert_P20_Into_Space (string);
check_string (string, results[i]);
g_free (string);
}
}
static void
scan_insert_space (void)
{
gsize i;
const gchar * const cases[] = { "STRINGAB", "StRiNgAb", "tRßiNgAb", "AՄՆ",
"bՄԵ", "cՄԻ", "dՎՆ", "eՄԽ", "fꜲ" };
const gchar * const results[] = { "S T R I N G A B", "St Ri Ng Ab",
"t Rßi Ng Ab", "A Մ Ն", "b Մ Ե", "c Մ Ի",
"d Վ Ն", "e Մ Խ", "f Ꜳ" };
for (i = 0; i < G_N_ELEMENTS (cases); i++)
{
gchar *string;
string = Scan_Process_Fields_Insert_Space (cases[i]);
check_string (string, results[i]);
g_free (string);
}
}
static void
scan_all_uppercase (void)
{
gsize i;
const gchar * const cases[] = { "stringab", "tRßiNgAb", "aʼnbcd", "lowΐer",
"uppΰer", "sTRINGև", "ᾖᾀ", "pᾖp",
"sAfflAs" };
const gchar * const results[] = { "STRINGAB", "TRSSINGAB", "AʼNBCD",
"LOWΪ́ER", "UPPΫ́ER", "STRINGԵՒ", "ἮΙἈΙ",
"PἮΙP", "SAFFLAS" };
for (i = 0; i < G_N_ELEMENTS (cases); i++)
{
gchar *string;
string = Scan_Process_Fields_All_Uppercase (cases[i]);
check_string (string, results[i]);
g_free (string);
}
}
static void
scan_all_lowercase (void)
{
gsize i;
const gchar * const cases[] = { "STRINGAB", "tRßiNgAb", "SMALLß",
"AAAԵՒBB", "ʼN", "PΪ́E", "ἮΙ", "Ϋ́E" };
const gchar * const results[] = { "stringab", "trßingab", "smallß",
"aaaեւbb", "ʼn", "pΐe", "ἦι", "ΰe" };
for (i = 0; i < G_N_ELEMENTS (cases); i++)
{
gchar *string;
string = Scan_Process_Fields_All_Downcase (cases[i]);
check_string (string, results[i]);
g_free (string);
}
}
static void
scan_letter_uppercase (void)
{
gsize i;
const gchar * const cases[] = { "st ri ng in ab", "tr ßi ng ab",
"ßr ßi ng ab", "ßr i ng ab", "ßr mi ng ab",
"I I ng ab", "ß I ng ab", "ßi ng ab" };
const gchar * const results[] = { "St ri ng in ab", "Tr ßi ng ab",
"SSr ßi ng ab", "SSr I ng ab",
"SSr mi ng ab", "I I ng ab",
"SS I ng ab", "SSi ng ab" };
for (i = 0; i < G_N_ELEMENTS (cases); i++)
{
gchar *string;
string = Scan_Process_Fields_Letter_Uppercase (cases[i]);
check_string (string, results[i]);
g_free (string);
}
}
static void
scan_letters_uppercase (void)
{
gsize i;
const gchar * const cases[] = { "Foo Bar The Baz", "The", "The The",
"The The The", "Vibrate (single version)",
"MCMXC", "Foo Bar The III (single version)",
"01 02 Caps" };
const gchar * const results[] = { "Foo Bar the Baz", "The", "The The",
"The the The",
"Vibrate (Single Version)", "Mcmxc",
"Foo Bar the Iii (Single Version)",
"01 02 Caps" };
const gchar * const results_roman[] = { "Foo Bar the Baz", "The",
"The The", "The the The",
"Vibrate (Single Version)",
"MCMXC",
"Foo Bar the III (Single Version)",
"01 02 Caps" };
const gchar * const results_preps[] = { "Foo Bar The Baz", "The",
"The The", "The The The",
"Vibrate (Single Version)",
"Mcmxc",
"Foo Bar The Iii (Single Version)",
"01 02 Caps" };
const gchar * const results_preps_roman[] = { "Foo Bar The Baz", "The",
"The The", "The The The",
"Vibrate (Single Version)",
"MCMXC",
"Foo Bar The III (Single Version)",
"01 02 Caps" };
for (i = 0; i < G_N_ELEMENTS (cases); i++)
{
gchar *string;
/* Lower-case exempted words, do not handle Roman numerals. */
string = g_strdup (cases[i]);
Scan_Process_Fields_First_Letters_Uppercase (&string, FALSE, FALSE);
check_string (string, results[i]);
g_free (string);
/* Lower-case exempted words, handle Roman numerals. */
string = g_strdup (cases[i]);
Scan_Process_Fields_First_Letters_Uppercase (&string, FALSE, TRUE);
check_string (string, results_roman[i]);
g_free (string);
/* Upper-case all words, do not handle Roman numerals. */
string = g_strdup (cases[i]);
Scan_Process_Fields_First_Letters_Uppercase (&string, TRUE, FALSE);
check_string (string, results_preps[i]);
g_free (string);
/* Upper-case all words, handle Roman numerals. */
string = g_strdup (cases[i]);
Scan_Process_Fields_First_Letters_Uppercase (&string, TRUE, TRUE);
check_string (string, results_preps_roman[i]);
g_free (string);
}
}
static void
scan_perf (gconstpointer user_data)
{
gsize i;
gdouble time;
g_test_timer_start ();
for (i = 0; i < PERF_ITERATIONS; i++)
{
((GTestFunc)user_data) ();
}
time = g_test_timer_elapsed ();
g_test_minimized_result (time, "%6.1f seconds", time);
}
int
main (int argc, char** argv)
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/scan/underscore-to-space", scan_underscore_to_space);
g_test_add_func ("/scan/remove-space", scan_remove_space);
g_test_add_func ("/scan/P20-to-space", scan_p20_to_space);
g_test_add_func ("/scan/insert-space", scan_insert_space);
g_test_add_func ("/scan/all-uppercase", scan_all_uppercase);
g_test_add_func ("/scan/all-lowercase", scan_all_lowercase);
g_test_add_func ("/scan/letter-uppercase", scan_letter_uppercase);
g_test_add_func ("/scan/letters-uppercase", scan_letters_uppercase);
if (g_test_perf ())
{
g_test_add_data_func ("/scan/perf/underscore-to-space",
scan_underscore_to_space, scan_perf);
g_test_add_data_func ("/scan/perf/remove-space", scan_remove_space,
scan_perf);
g_test_add_data_func ("/scan/perf/P20-to-space", scan_p20_to_space,
scan_perf);
g_test_add_data_func ("/scan/perf/insert-space", scan_insert_space,
scan_perf);
g_test_add_data_func ("/scan/perf/all-uppercase", scan_all_uppercase,
scan_perf);
g_test_add_data_func ("/scan/perf/all-lowercase", scan_all_lowercase,
scan_perf);
g_test_add_data_func ("/scan/perf/letter-uppercase",
scan_letter_uppercase, scan_perf);
g_test_add_data_func ("/scan/perf/letters-uppercase",
scan_letters_uppercase, scan_perf);
}
return g_test_run ();
}
|