[easytag] Use const for strings in tests and libapetag
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag] Use const for strings in tests and libapetag
- Date: Fri, 19 Sep 2014 15:49:43 +0000 (UTC)
commit 9add9cf7c5ec6ce431c513a17922962118c8f5a7
Author: David King <amigadave amigadave com>
Date: Fri Sep 19 16:46:37 2014 +0100
Use const for strings in tests and libapetag
src/tags/libapetag/apetaglib.c | 10 ++--
src/tags/libapetag/apetaglib.h | 6 +-
tests/test-scan.c | 128 +++++++++++++++++++++-------------------
3 files changed, 76 insertions(+), 68 deletions(-)
---
diff --git a/src/tags/libapetag/apetaglib.c b/src/tags/libapetag/apetaglib.c
index 3bcf83e..fbb0a66 100644
--- a/src/tags/libapetag/apetaglib.c
+++ b/src/tags/libapetag/apetaglib.c
@@ -273,8 +273,8 @@ libapetag_maloc_cont_text (apetag *mem_cnt, unsigned long flags,
\return 0 - OK else check #atl_return
*/
int
-apefrm_add (apetag *mem_cnt, unsigned long flags, char *name,
- char *value)
+apefrm_add (apetag *mem_cnt, unsigned long flags, const char *name,
+ const char *value)
{
apefrm_remove_real (mem_cnt, name);
return libapetag_maloc_cont (mem_cnt, flags, strlen (name), name, strlen (value), value);
@@ -433,7 +433,7 @@ apefrm_getstr (apetag *mem_cnt, const char *name)
\param name frame name for search and remove
*/
void
-apefrm_remove_real (apetag *mem_cnt, char *name)
+apefrm_remove_real (apetag *mem_cnt, const char *name)
{
int n;
struct tag **mTag;
@@ -482,7 +482,7 @@ apefrm_remove_real (apetag *mem_cnt, char *name)
\param name frame name for search and remove
*/
void
-apefrm_remove (apetag *mem_cnt, char *name)
+apefrm_remove (apetag *mem_cnt, const char *name)
{
int n;
struct tag **mTag;
@@ -838,7 +838,7 @@ apetag_read (apetag *mem_cnt, const char *filename, int flag)
static int
libapetag_qsort (struct tag **a, struct tag **b)
{
- char *sorting[] = { "Artist", "Year", "Album", "Track", "Title", "Genre", NULL, NULL };
+ const char * const sorting[] = { "Artist", "Year", "Album", "Track", "Title", "Genre", NULL, NULL };
int n, m;
if (!a || !b || !*a || !*b) {
diff --git a/src/tags/libapetag/apetaglib.h b/src/tags/libapetag/apetaglib.h
index 3bc97d3..e8ac4cd 100644
--- a/src/tags/libapetag/apetaglib.h
+++ b/src/tags/libapetag/apetaglib.h
@@ -212,7 +212,7 @@ apetag_save (char *filename, apetag *mem_cnt, int flag) ;
/* Add text frame */
int
-apefrm_add (apetag *mem_cnt, unsigned long flags, char *name, char *value) ;
+apefrm_add (apetag *mem_cnt, unsigned long flags, const char *name, const char *value) ;
/* add binary frame */
int
@@ -233,7 +233,7 @@ apefrm_getstr (apetag *mem_cnt, const char *name) ;
/* remove frame from memory */
void
-apefrm_remove_real (apetag *mem_cnt, char *name) ;
+apefrm_remove_real (apetag *mem_cnt, const char *name) ;
/**
@@ -245,7 +245,7 @@ apefrm_remove_real (apetag *mem_cnt, char *name) ;
/* set frame to remove */
void
-apefrm_remove (apetag *mem_cnt, char *name);
+apefrm_remove (apetag *mem_cnt, const char *name);
/* read id3v1 and add frames */
int
diff --git a/tests/test-scan.c b/tests/test-scan.c
index 802b0e9..3c2e06b 100644
--- a/tests/test-scan.c
+++ b/tests/test-scan.c
@@ -24,7 +24,7 @@
static const gsize PERF_ITERATIONS = 500000;
static void
-check_string (gchar *cases, gchar *result)
+check_string (const gchar *cases, const gchar *result)
{
gchar *string1, *string2;
@@ -41,8 +41,8 @@ static void
scan_underscore_to_space (void)
{
gsize i;
- gchar *cases[] = {" ်0STRING ်0_A_B"};
- gchar *results[] = {" ်0STRING ်0 A B"};
+ 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++)
{
@@ -60,8 +60,8 @@ static void
scan_remove_space (void)
{
gsize i;
- gchar *cases[] = { " STR ING A B " };
- gchar *results[] = { "STRINGAB" };
+ const gchar * const cases[] = { " STR ING A B " };
+ const gchar * const results[] = { "STRINGAB" };
for (i = 0; i < G_N_ELEMENTS (cases); i++)
{
@@ -79,8 +79,9 @@ static void
scan_p20_to_space (void)
{
gsize i;
- gchar *cases[] = { "S%20T%20R%20", "%20ă b %20c", "STЂR%20ING%20A%20B" };
- gchar *results[] = { "S T R ", " ă b c", "STЂR ING A B" };
+ 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++)
{
@@ -98,21 +99,20 @@ static void
scan_insert_space (void)
{
gsize i;
- gchar *cases[] = { "STRINGAB", "StRiNgAb", "tRßiNgAb", "AՄՆ", "bՄԵ", "cՄԻ",
- "dՎՆ", "eՄԽ", "fꜲ"};
- gchar *results[] = { "S T R I N G A B", "St Ri Ng Ab", "t Rßi Ng Ab",
- "A Մ Ն", "b Մ Ե", "c Մ Ի", "d Վ Ն", "e Մ Խ", "f Ꜳ" };
+ 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, *res;
+ gchar *string;
- string = g_strdup (cases[i]);
- res = Scan_Process_Fields_Insert_Space (string);
- check_string (res, results[i]);
+ string = Scan_Process_Fields_Insert_Space (cases[i]);
+ check_string (string, results[i]);
g_free (string);
- g_free (res);
}
}
@@ -120,21 +120,21 @@ static void
scan_all_uppercase (void)
{
gsize i;
- gchar *cases[] = { "stringab", "tRßiNgAb", "aʼnbcd", "lowΐer", "uppΰer",
- "sTRINGև", "ᾖᾀ", "pᾖp", "sAfflAs" };
- gchar *results[] = { "STRINGAB", "TRSSINGAB", "AʼNBCD", "LOWΪ́ER", "UPPΫ́ER",
- "STRINGԵՒ", "ἮΙἈΙ", "PἮΙP", "SAFFLAS" };
+ 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, *res;
+ gchar *string;
- string = g_strdup (cases[i]);
- res = Scan_Process_Fields_All_Uppercase (string);
- check_string (res, results[i]);
+ string = Scan_Process_Fields_All_Uppercase (cases[i]);
+ check_string (string, results[i]);
g_free (string);
- g_free (res);
}
}
@@ -142,21 +142,19 @@ static void
scan_all_lowercase (void)
{
gsize i;
- gchar *cases[] = { "STRINGAB", "tRßiNgAb", "SMALLß", "AAAԵՒBB", "ʼN",
- "PΪ́E", "ἮΙ", "Ϋ́E" };
- gchar *results[] = { "stringab", "trßingab", "smallß", "aaaեւbb", "ʼn",
- "pΐe", "ἦι", "ΰe" };
+ 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, *res;
+ gchar *string;
- string = g_strdup (cases[i]);
- res = Scan_Process_Fields_All_Downcase (string);
- check_string (res, results[i]);
+ string = Scan_Process_Fields_All_Downcase (cases[i]);
+ check_string (string, results[i]);
g_free (string);
- g_free (res);
}
}
@@ -164,23 +162,22 @@ static void
scan_letter_uppercase (void)
{
gsize i;
- gchar *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" };
- gchar *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" };
+ 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, *res;
+ gchar *string;
- string = g_strdup (cases[i]);
- res = Scan_Process_Fields_Letter_Uppercase (string);
- check_string (res, results[i]);
+ string = Scan_Process_Fields_Letter_Uppercase (cases[i]);
+ check_string (string, results[i]);
g_free (string);
- g_free (res);
}
}
@@ -188,22 +185,33 @@ static void
scan_letters_uppercase (void)
{
gsize i;
- const gchar *cases[] = { "Foo Bar The Baz", "The", "The The",
+ const gchar * const cases[] = { "Foo Bar The Baz", "The", "The The",
"The The The", "Vibrate (single version)",
- "MCMXC", "Foo Bar The III (single version)" };
- gchar *results[] = { "Foo Bar the Baz", "The", "The The", "The the The",
- "Vibrate (Single Version)", "Mcmxc",
- "Foo Bar the Iii (Single Version)" };
- gchar *results_roman[] = { "Foo Bar the Baz", "The", "The The",
- "The the The", "Vibrate (Single Version)",
- "MCMXC", "Foo Bar the III (Single Version)" };
- gchar *results_preps[] = { "Foo Bar The Baz", "The", "The The",
- "The The The", "Vibrate (Single Version)",
- "Mcmxc", "Foo Bar The Iii (Single Version)" };
- gchar *results_preps_roman[] = { "Foo Bar The Baz", "The", "The The",
- "The The The", "Vibrate (Single Version)",
- "MCMXC",
- "Foo Bar The III (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++)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]