From 25863489218ef523ff57a7302cbfb2fc1101a5cf Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 17 Dec 2015 10:32:01 -0500 Subject: [PATCH] core/audio: Convert file to C I also convert core/core.c so the audio test can be converted at the same time. Signed-off-by: Anna Schumaker --- core/Sconscript | 2 +- core/{audio.cpp => audio.c} | 7 +-- core/{core.cpp => core.c} | 4 +- core/tags/Sconscript | 2 +- gui/gst.cpp | 3 +- gui/ocarina.cpp | 2 +- gui/playlist.cpp | 2 +- gui/queue/model.cpp | 2 +- gui/window.cpp | 2 +- include/core/audio.h | 7 +-- include/core/core.h | 3 +- include/tests/test.h | 2 + tests/core/Sconscript | 8 +-- tests/core/{audio.cpp => audio.c} | 89 ++++++++++++++++--------------- 14 files changed, 61 insertions(+), 74 deletions(-) rename core/{audio.cpp => audio.c} (99%) rename core/{core.cpp => core.c} (97%) rename tests/core/{audio.cpp => audio.c} (71%) diff --git a/core/Sconscript b/core/Sconscript index fef823db..42b0d2d3 100644 --- a/core/Sconscript +++ b/core/Sconscript @@ -1,5 +1,5 @@ #!/usr/bin/python -res = Glob("*.cpp") + Glob("*.c") +res = Glob("*.c") res += SConscript("tags/Sconscript") res += SConscript("containers/Sconscript") Return("res") diff --git a/core/audio.cpp b/core/audio.c similarity index 99% rename from core/audio.cpp rename to core/audio.c index 5fcdcb4c..a5a5899e 100644 --- a/core/audio.cpp +++ b/core/audio.c @@ -1,14 +1,10 @@ -/** +/* * Copyright 2013 (c) Anna Schumaker. */ #include -extern "C" { #include #include #include -#include -} - static struct file audio_file; static struct track *audio_track = NULL; @@ -17,6 +13,7 @@ static struct audio_ops *audio_ops = NULL; static int audio_pause_count = -1; static guint audio_bus = 0; + static void __audio_save() { file_open(&audio_file, OPEN_WRITE); diff --git a/core/core.cpp b/core/core.c similarity index 97% rename from core/core.cpp rename to core/core.c index 1c73e5a9..283e446a 100644 --- a/core/core.cpp +++ b/core/core.c @@ -1,16 +1,14 @@ -/** +/* * Copyright 2014 (c) Anna Schumaker. */ #include #include -extern "C" { #include #include #include #include #include #include -} void core_init(int *argc, char ***argv, struct core_init_data *init) diff --git a/core/tags/Sconscript b/core/tags/Sconscript index 0cf4bb59..33d0a110 100644 --- a/core/tags/Sconscript +++ b/core/tags/Sconscript @@ -2,5 +2,5 @@ Import("env") env.UsePackage("taglib_c") -res = Glob("*.cpp") + Glob("*.c") +res = Glob("*.c") Return("res") diff --git a/gui/gst.cpp b/gui/gst.cpp index 3da7ded4..9a9e4e00 100644 --- a/gui/gst.cpp +++ b/gui/gst.cpp @@ -5,9 +5,8 @@ * through argv. Use the command `gst-inspect-1.0 --help-gst` to find * what options are supported. */ -#include extern "C" { -#include +#include #include } #include diff --git a/gui/ocarina.cpp b/gui/ocarina.cpp index d961412a..5b0e6840 100644 --- a/gui/ocarina.cpp +++ b/gui/ocarina.cpp @@ -1,8 +1,8 @@ /* * Copyright 2014 (c) Anna Schumaker. */ -#include extern "C" { +#include #include } #include diff --git a/gui/playlist.cpp b/gui/playlist.cpp index e5bb8a77..da1ce1d0 100644 --- a/gui/playlist.cpp +++ b/gui/playlist.cpp @@ -1,8 +1,8 @@ /* * Copyright 2014 (c) Anna Schumaker. */ -#include extern "C" { +#include #include #include } diff --git a/gui/queue/model.cpp b/gui/queue/model.cpp index 9d50ed73..7b32f085 100644 --- a/gui/queue/model.cpp +++ b/gui/queue/model.cpp @@ -4,8 +4,8 @@ * See the example at: * https://git.gnome.org/browse/gtkmm-documentation/tree/examples/others/treemodelcustom */ -#include extern "C" { +#include #include } #include diff --git a/gui/window.cpp b/gui/window.cpp index 2c5bc358..0c7c71b6 100644 --- a/gui/window.cpp +++ b/gui/window.cpp @@ -1,8 +1,8 @@ /* * Copyright 2014 (c) Anna Schumaker. */ -#include extern "C" { +#include #include #include } diff --git a/include/core/audio.h b/include/core/audio.h index 41922ccd..90ad988e 100644 --- a/include/core/audio.h +++ b/include/core/audio.h @@ -1,15 +1,10 @@ -/** +/* * Copyright 2013 (c) Anna Schumaker. */ #ifndef OCARINA_CORE_AUDIO_H #define OCARINA_CORE_AUDIO_H - -extern "C" { #include -} #include -#include -#include struct audio_ops { diff --git a/include/core/core.h b/include/core/core.h index 45580219..75a3c14a 100644 --- a/include/core/core.h +++ b/include/core/core.h @@ -1,9 +1,8 @@ -/** +/* * Copyright 2014 (c) Anna Schumaker. */ #ifndef OCARINA_CORE_CORE_H #define OCARINA_CORE_CORE_H - #include diff --git a/include/tests/test.h b/include/tests/test.h index ee386f35..bd942cf8 100644 --- a/include/tests/test.h +++ b/include/tests/test.h @@ -15,6 +15,7 @@ #ifndef __cplusplus static inline gchar *stos(const char *s) { return g_strdup(s); } static inline gchar *utos(unsigned int u) { return g_strdup_printf("%u", u); } +static inline gchar *ltos(long int l) { return g_strdup_printf("%lu", l); } static inline gchar *itos(int i) { return g_strdup_printf("%i", i); } static inline gchar *ftos(float f) { return g_strdup_printf("%f", f); } static inline gchar *btos(bool b) { return g_strdup(b ? "true" : "false"); } @@ -26,6 +27,7 @@ static inline gchar *ptos(void *p) { return g_strdup_printf("%p", p); } const char *: stos, \ bool: btos, \ unsigned int: utos, \ + long int: ltos, \ int: itos, \ float:ftos, \ void *:ptos \ diff --git a/tests/core/Sconscript b/tests/core/Sconscript index 6c40ff20..e0909d82 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -8,11 +8,7 @@ core_objs = [] def CoreTest(name): global core_objs - test = name.split("/")[-1] - source = "%s.c" % test - if os.path.exists("%s.cpp" % test): - source = "%s.cpp" % test - + source = "%s.c" % name.split("/")[-1] test = os.path.abspath(source) core = os.path.sep.join([x for x in test.split("/") if x != "tests"]) if os.path.exists(core): @@ -43,7 +39,7 @@ res += [ CoreTest("collection") ] res += [ CoreTest("history") ] res += [ CoreTest("tempq") ] -core_objs += [ env.Object("../../core/core.cpp") ] +core_objs += [ env.Object("../../core/core.c") ] res += [ CoreTest("audio") ] Return("res") diff --git a/tests/core/audio.cpp b/tests/core/audio.c similarity index 71% rename from tests/core/audio.cpp rename to tests/core/audio.c index 002ecd4f..8c6e08fb 100644 --- a/tests/core/audio.cpp +++ b/tests/core/audio.c @@ -2,14 +2,12 @@ * Copyright 2013 (c) Anna Schumaker. */ #include -extern "C" { #include #include #include #include -} #include -#include "test.h" +#include static unsigned int load_count = 0; static int pause_count = 0; @@ -63,72 +61,72 @@ static struct core_init_data test_init_data = { static void test_init() { - test_equal(audio_get_player(), NULL); - test_equal(audio_cur_track(), NULL); + test_equal((void *)audio_get_player(), NULL); + test_equal((void *)audio_cur_track(), NULL); test_equal(audio_cur_state(), GST_STATE_NULL); - test_equal(audio_next(), NULL); + test_equal((void *)audio_next(), NULL); core_init(NULL, NULL, &test_init_data); - test_equal(audio_load(NULL), false); - test_equal(audio_next(), NULL); - test_equal(audio_prev(), NULL); + test_equal(audio_load(NULL), (bool)false); + test_equal((void *)audio_next(), NULL); + test_equal((void *)audio_prev(), NULL); test_send_error(); - test_equal(audio_play(), false); - test_equal(audio_pause(), false); - test_equal(audio_stop(), false); - test_equal(audio_seek(7), false); + test_equal(audio_play(), (bool)false); + test_equal(audio_pause(), (bool)false); + test_equal(audio_stop(), (bool)false); + test_equal(audio_seek(7), (bool)false); test_equal(audio_position(), 0); test_equal(audio_duration(), 0); - test_equal(audio_cur_track(), NULL); + test_equal((void *)audio_cur_track(), NULL); test_equal(audio_cur_state(), GST_STATE_NULL); test_equal(load_count, 0); collection_add("tests/Music/Hyrule Symphony"); while (idle_run_task()) {}; - test_equal(audio_cur_track(), NULL); - test_not_equal(audio_get_player(), NULL); + test_equal((void *)audio_cur_track(), NULL); + test_not_equal((void *)audio_get_player(), NULL); } static void test_playback() { - test_equal(audio_load(track_get(0)), true); + test_equal(audio_load(track_get(0)), (bool)true); test_equal(load_count, 1); - test_equal(audio_cur_track(), track_get(0)); + test_equal((void *)audio_cur_track(), (void *)track_get(0)); test_equal(audio_cur_state(), GST_STATE_NULL); test_equal(queue_size(history_get_queue()), 1); test_equal(audio_duration(), track_get(0)->tr_length * GST_SECOND); - test_equal(audio_load(NULL), false); + test_equal(audio_load(NULL), (bool)false); test_equal(load_count, 1); - test_equal(audio_cur_track(), track_get(0)); + test_equal((void *)audio_cur_track(), (void *)track_get(0)); test_equal(queue_size(history_get_queue()), 1); - test_equal(audio_load(track_get(0)), false); + test_equal(audio_load(track_get(0)), (bool)false); test_equal(load_count, 1); test_equal(queue_size(history_get_queue()), 1); - test_equal(audio_play(), true); - test_equal(audio_play(), false); + test_equal(audio_play(), (bool)true); + test_equal(audio_play(), (bool)false); test_equal(audio_cur_state(), GST_STATE_PLAYING); - test_equal(audio_pause(), true); - test_equal(audio_pause(), false); + test_equal(audio_pause(), (bool)true); + test_equal(audio_pause(), (bool)false); test_equal(audio_cur_state(), GST_STATE_PAUSED); - test_equal(test_audio_seek(5 * GST_SECOND), true); + test_equal(test_audio_seek(5 * GST_SECOND), (bool)true); test_equal(audio_position(), 5 * GST_SECOND); - test_equal(audio_stop(), true); + test_equal(audio_stop(), (bool)true); test_equal(audio_position(), 0); test_equal(audio_cur_state(), GST_STATE_PAUSED); - test_equal(test_audio_seek(42 * GST_SECOND), true); + test_equal(test_audio_seek(42 * GST_SECOND), (bool)true); test_equal(audio_position(), 42 * GST_SECOND); - test_equal(audio_play(), true); - test_equal(audio_stop(), true); + test_equal(audio_play(), (bool)true); + test_equal(audio_stop(), (bool)true); test_equal(audio_cur_state(), GST_STATE_PAUSED); test_equal(audio_position(), 0); @@ -153,14 +151,16 @@ static void test_next() test_loop_equal(audio_next()->tr_dbe.dbe_index, i, i); } else /* Simulate an error. */ test_send_error(); - test_loop_equal(queue_at(history_q, 0), track_get(i), i); + test_loop_equal((void *)queue_at(history_q, 0), + (void *)track_get(i), i); test_loop_equal(audio_cur_state(), GST_STATE_PAUSED, i); - test_loop_equal(audio_cur_track(), track_get(i), i); + test_loop_equal((void *)audio_cur_track(), + (void *)track_get(i), i); } test_loop_passed(); - test_equal(tempq_get(0), NULL); + test_equal((void *)tempq_get(0), NULL); /* Tracks should now be picked from the collection. */ - test_equal(audio_play(), true); + test_equal(audio_play(), (bool)true); for (i = 1; i <= 3; i++) { if (i < 3) { test_loop_equal(audio_next()->tr_track, i, i); @@ -178,28 +178,28 @@ static void test_prev() struct track *track = queue_at(history_q, 0); test_equal(audio_prev()->tr_track, 2); - test_equal(queue_at(history_q, 0), track); + test_equal((void *)queue_at(history_q, 0), (void *)track); test_equal(audio_cur_state(), GST_STATE_PLAYING); test_equal(audio_cur_track()->tr_track, 2); test_equal(audio_prev()->tr_track, 1); - test_equal(queue_at(history_q, 0), track); + test_equal((void *)queue_at(history_q, 0), (void *)track); test_equal(audio_cur_state(), GST_STATE_PLAYING); test_equal(audio_cur_track()->tr_track, 1); - test_equal(audio_pause(), true); + test_equal(audio_pause(), (bool)true); test_equal(audio_prev()->tr_dbe.dbe_index, 0); - test_equal(queue_at(history_q, 0), track); + test_equal((void *)queue_at(history_q, 0), (void *)track); test_equal(audio_cur_state(), GST_STATE_PAUSED); test_equal(audio_cur_track()->tr_dbe.dbe_index, 0); test_equal(audio_prev()->tr_dbe.dbe_index, 1); - test_equal(queue_at(history_q, 0), track); + test_equal((void *)queue_at(history_q, 0), (void *)track); test_equal(audio_cur_state(), GST_STATE_PAUSED); test_equal(audio_cur_track()->tr_dbe.dbe_index, 1); test_equal(audio_prev()->tr_dbe.dbe_index, 2); - test_equal(queue_at(history_q, 0), track); + test_equal((void *)queue_at(history_q, 0), (void *)track); test_equal(audio_cur_state(), GST_STATE_PAUSED); test_equal(audio_cur_track()->tr_dbe.dbe_index, 2); } @@ -209,7 +209,7 @@ void test_autopause() struct queue *history_q = history_get_queue(); int i; - test_equal(audio_play(), true); + test_equal(audio_play(), (bool)true); test_equal(pause_count, 0); audio_pause_after(3); @@ -226,7 +226,8 @@ void test_autopause() audio_eos(); test_loop_equal(pause_count, i, i); test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i); - test_loop_equal(queue_at(history_q, 0), audio_cur_track(), i); + test_loop_equal((void *)queue_at(history_q, 0), + (void *)audio_cur_track(), i); } test_loop_passed(); audio_eos(); @@ -237,8 +238,8 @@ void test_autopause() static void test_deinit() { core_deinit(); - test_equal(audio_cur_track(), NULL); - test_equal(audio_get_player(), NULL); + test_equal((void *)audio_cur_track(), NULL); + test_equal((void *)audio_get_player(), NULL); }