Compile tests as C++

This commit is contained in:
Yevgen Muntyan 2016-10-23 12:43:28 -07:00
parent 42bc3686d7
commit a48117407f
23 changed files with 680 additions and 580 deletions

View File

@ -9,7 +9,7 @@ tmpl_file_start = """\
%(headers)s
#include "moolua/moo-lua-api-util.h"
extern "C" void moo_test_coverage_record (const char *lang, const char *function);
void moo_test_coverage_record (const char *lang, const char *function);
"""

View File

@ -822,7 +822,7 @@ medit_main (int argc, char *argv[])
#else
{
fputs ("medit was built without project support\n", stderr);
exit (EXIT_FAILURE);
exit (EXIT_FAILURE);
}
#endif
else

64
moo/moocpp/fileutils.cpp Normal file
View File

@ -0,0 +1,64 @@
/*
* gutil.h
*
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
*
* This file is part of medit. medit is free software; you can
* redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "moocpp/fileutils.h"
gstr g::build_filename(const gstr& comp1, const gstr& comp2)
{
return gstr::take(g_build_filename(comp1.get(), comp2.get(), nullptr));
}
gstr g::build_filename(const gstr& comp1, const gstr& comp2, const gstr& comp3)
{
return gstr::take(g_build_filename(comp1.get(), comp2.get(), comp3.get(), nullptr));
}
gstr g::build_filename(const gstr& comp1, const gstr& comp2, const gstr& comp3, const gstr& comp4)
{
return gstr::take(g_build_filename(comp1.get(), comp2.get(), comp3.get(), comp4.get(), nullptr));
}
gstr g::build_filename(const gstr& comp1, const gstr& comp2, const gstr& comp3, const gstr& comp4, const gstr& comp5)
{
return gstr::take(g_build_filename(comp1.get(), comp2.get(), comp3.get(), comp4.get(), comp5.get(), nullptr));
}
gstr g::build_filenamev(const std::vector<gstr>& components)
{
GPtrArray* strv = g_ptr_array_new_full(components.size() + 1, nullptr);
for (const auto& comp: components)
g_ptr_array_add(strv, const_cast<char*>(comp.get()));
g_ptr_array_add(strv, nullptr);
gstr result = gstr::take(g_build_filenamev((char**) strv->pdata));
g_ptr_array_free(strv, true);
return result;
}
gstr g::get_current_dir()
{
return gstr::take(g_get_current_dir());
}
gstr g::path_get_basename(const gchar *file_name)
{
return gstr::take(g_path_get_basename(file_name));
}
gstr g::path_get_dirname(const gchar *file_name)
{
return gstr::take(g_path_get_dirname(file_name));
}

34
moo/moocpp/fileutils.h Normal file
View File

@ -0,0 +1,34 @@
/*
* gutil.h
*
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
*
* This file is part of medit. medit is free software; you can
* redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <glib.h>
#include <moocpp/gstr.h>
namespace g
{
gstr build_filename(const gstr& comp1, const gstr& comp2);
gstr build_filename(const gstr& comp1, const gstr& comp2, const gstr& comp3);
gstr build_filename(const gstr& comp1, const gstr& comp2, const gstr& comp3, const gstr& comp4);
gstr build_filename(const gstr& comp1, const gstr& comp2, const gstr& comp3, const gstr& comp4, const gstr& comp5);
gstr build_filenamev(const std::vector<gstr>& components);
gstr get_current_dir();
gstr path_get_basename(const gchar *file_name);
gstr path_get_dirname(const gchar *file_name);
gstr get_current_dir();
} // namespace g

142
moo/moocpp/gstr.cpp Normal file
View File

@ -0,0 +1,142 @@
/*
* gstr.cpp
*
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
*
* This file is part of medit. medit is free software; you can
* redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "gstr.h"
gstr::gstr()
: m_p(nullptr)
{
}
gstr::gstr(nullptr_t)
: gstr()
{
}
gstr::~gstr()
{
g_free(m_p);
}
gstr::gstr(const char* s)
: gstr()
{
*this = s;
}
gstr::gstr(char* s, bool)
: m_p(s)
{
}
gstr::gstr(const gstr& s)
: gstr()
{
*this = s;
}
gstr::gstr(gstr&& s)
: gstr()
{
steal(s.m_p);
s.m_p = nullptr;
}
const char* gstr::get() const
{
return m_p ? m_p : "";
}
void gstr::steal(char* s)
{
g_free(m_p);
m_p = s ? g_strdup(s) : nullptr;
}
gstr gstr::take(char* src)
{
return gstr(src, true);
}
gstr& gstr::operator=(const gstr& other)
{
if (this != &other)
*this = other.m_p;
return *this;
}
gstr& gstr::operator=(const char* other)
{
if (m_p != other)
{
g_free(m_p);
m_p = other ? g_strdup(other) : nullptr;
}
return *this;
}
gstr& gstr::operator=(gstr&& other)
{
steal(other.m_p);
other.m_p = nullptr;
return *this;
}
void gstr::clear()
{
*this = nullptr;
}
bool gstr::empty() const
{
return !m_p || !*m_p;
}
bool gstr::operator==(const gstr& other) const
{
return strcmp(get(), other.get()) == 0;
}
bool gstr::operator==(const char* other) const
{
return strcmp(get(), other ? other : "") == 0;
}
bool gstr::operator==(nullptr_t) const
{
return empty();
}
bool gstr::operator<(const gstr& other) const
{
return strcmp(get(), other.get()) < 0;
}
std::vector<gstr> gstr::from_strv(char** strv)
{
size_t len = strv ? g_strv_length(strv) : 0;
std::vector<gstr> result;
result.reserve(len);
for (size_t i = 0; i < len; ++i)
result.push_back(strv[i]);
return result;
}
std::vector<gstr> gstr::split(const char* separator, int max_pieces) const
{
return from_strv(g_strsplit(get(), separator, max_pieces));
}

View File

@ -16,112 +16,63 @@
#pragma once
#include <glib.h>
#include <string.h>
#include <vector>
class gstr
{
public:
gstr()
: m_p(nullptr)
{
}
gstr();
gstr(nullptr_t);
gstr(const char* s);
gstr(char* s, bool);
~gstr();
gstr(nullptr_t)
: gstr()
{
}
gstr(const gstr& s);
gstr(gstr&& s);
~gstr()
{
g_free(m_p);
}
const char* get() const;
gstr(const char* s)
: gstr()
{
*this = s;
}
void steal(char* s);
static gstr take(char* src);
gstr(const gstr& s)
: gstr()
{
*this = s;
}
gstr& operator=(const gstr& other);
gstr& operator=(const char* other);
gstr& operator=(gstr&& other);
gstr(gstr&& s)
: gstr()
{
steal(s.m_p);
s.m_p = nullptr;
}
const char* get() const
{
return m_p ? m_p : "";
}
void steal(char* s)
{
g_free(m_p);
m_p = s ? g_strdup(s) : nullptr;
}
static gstr take(char* src)
{
gstr result;
result.steal(src);
return result;
}
gstr& operator=(const gstr& other)
{
if (this != &other)
*this = other.m_p;
return *this;
}
gstr& operator=(const char* other)
{
if (m_p != other)
{
g_free(m_p);
m_p = other ? g_strdup(other) : nullptr;
}
return *this;
}
gstr& operator=(gstr&& other)
{
steal(other.m_p);
other.m_p = nullptr;
return *this;
}
bool empty() const
{
return !m_p || !*m_p;
}
bool operator==(const gstr& other) const
{
return strcmp(get(), other.get()) == 0;
}
bool operator==(const char* other) const
{
return strcmp(get(), other ? other : "") == 0;
}
bool operator==(nullptr_t) const
{
return empty();
}
void clear();
bool empty() const;
bool operator==(const gstr& other) const;
bool operator==(const char* other) const;
bool operator==(nullptr_t) const;
template<typename T>
bool operator!=(const T& other) const
{
return !(*this == other);
}
bool operator<(const gstr& other) const;
static std::vector<gstr> from_strv(char** strv);
std::vector<gstr> split(const char* separator, int max_pieces) const;
private:
char* m_p;
};
namespace std
{
template<>
struct hash<gstr>
{
size_t operator()(const gstr& s) const
{
return g_str_hash(s.get());
}
};
} // namespace std

View File

@ -1,7 +1,10 @@
SET(moocpp_sources
moocpp/moocpp.cmake
moocpp/moocpp.cmake
moocpp/fileutils.h
moocpp/fileutils.cpp
moocpp/gobjptr.h
moocpp/gstr.h
moocpp/gstr.cpp
moocpp/moocpp.h
moocpp/util.h
)

View File

@ -2,10 +2,11 @@
#include "mooedit/mooeditor-impl.h"
#include "mooutils/mooutils-fs.h"
#include "mooutils/moohistorymgr.h"
#include "moocpp/fileutils.h"
static struct {
char *working_dir;
char *encodings_dir;
gstr working_dir;
gstr encodings_dir;
} test_data;
#ifdef __WIN32__
@ -22,13 +23,13 @@ static struct {
#define TT6 "lala\rlala\r"
static void
check_contents (const char *filename,
check_contents (const gstr& filename,
const char *expected)
{
char *contents;
GError *error = NULL;
if (!g_file_get_contents (filename, &contents, NULL, &error))
if (!g_file_get_contents (filename.get(), &contents, NULL, &error))
{
TEST_FAILED_MSG ("could not load file '%s': %s",
filename, error->message);
@ -47,12 +48,11 @@ test_basic (void)
MooEditor *editor;
MooEdit *doc, *doc2;
GtkTextBuffer *buffer;
char *filename;
MooOpenInfo *info;
editor = moo_editor_instance ();
filename = g_build_filename (test_data.working_dir, "test.txt", NULL);
info = moo_open_info_new (filename, NULL, -1, MOO_OPEN_FLAGS_NONE);
gstr filename = g::build_filename(test_data.working_dir, "test.txt");
info = moo_open_info_new(filename.get(), NULL, -1, MOO_OPEN_FLAGS_NONE);
doc = moo_editor_new_file (editor, info, NULL, NULL);
TEST_ASSERT (doc != NULL);
@ -77,35 +77,34 @@ test_basic (void)
TEST_ASSERT (moo_edit_save (doc, NULL));
check_contents (filename, TT3);
doc2 = moo_editor_open_path (editor, filename, NULL, -1, NULL);
doc2 = moo_editor_open_path (editor, filename.get(), NULL, -1, NULL);
TEST_ASSERT (doc2 == doc);
TEST_ASSERT (moo_edit_close (doc));
TEST_ASSERT (moo_editor_get_doc (editor, filename) == NULL);
TEST_ASSERT (moo_editor_get_doc (editor, filename.get()) == NULL);
g_file_set_contents (filename, TT4, -1, NULL);
doc = moo_editor_open_path (editor, filename, NULL, -1, NULL);
g_file_set_contents (filename.get(), TT4, -1, NULL);
doc = moo_editor_open_path (editor, filename.get(), NULL, -1, NULL);
TEST_ASSERT (doc != NULL);
TEST_ASSERT (moo_edit_save (doc, NULL));
check_contents (filename, TT4);
TEST_ASSERT (moo_edit_close (doc));
g_file_set_contents (filename, TT5, -1, NULL);
doc = moo_editor_open_path (editor, filename, NULL, -1, NULL);
g_file_set_contents (filename.get(), TT5, -1, NULL);
doc = moo_editor_open_path (editor, filename.get(), NULL, -1, NULL);
TEST_ASSERT (doc != NULL);
TEST_ASSERT (moo_edit_save (doc, NULL));
check_contents (filename, TT5);
TEST_ASSERT (moo_edit_close (doc));
g_file_set_contents (filename, TT6, -1, NULL);
doc = moo_editor_open_path (editor, filename, NULL, -1, NULL);
g_file_set_contents (filename.get(), TT6, -1, NULL);
doc = moo_editor_open_path (editor, filename.get(), NULL, -1, NULL);
TEST_ASSERT (doc != NULL);
TEST_ASSERT (moo_edit_save (doc, NULL));
check_contents (filename, TT6);
TEST_ASSERT (moo_edit_close (doc));
g_object_unref (info);
g_free (filename);
}
#define TEST_ASSERT_SAME_FILE_CONTENT(filename1, filename2) \
@ -136,48 +135,39 @@ static void
test_encodings_1 (const char *name,
const char *working_dir)
{
char *filename = NULL;
char *filename2 = NULL;
char *encoding = NULL;
const char *dot;
MooEditor *editor;
MooEdit *doc;
if ((dot = strchr (name, '.')))
encoding = g_strndup (name, dot - name);
gstr encoding;
if ((dot = strchr(name, '.')))
encoding.steal(g_strndup (name, dot - name));
else
encoding = g_strdup (name);
encoding = name;
#ifdef MOO_OS_WIN32
if (strcmp (encoding, "UTF-16") == 0 || strcmp (encoding, "UCS-4") == 0)
goto out;
if (encoding == "UTF-16" || encoding == "UCS-4")
return;
#endif
filename = g_build_filename (test_data.encodings_dir, name, (char*)0);
filename2 = g_build_filename (working_dir, name, (char*)0);
gstr filename = g::build_filename (test_data.encodings_dir, name);
gstr filename2 = g_build_filename (working_dir, name, (char*)0);
editor = moo_editor_instance ();
doc = moo_editor_open_path (editor, filename, encoding, -1, NULL);
doc = moo_editor_open_path (editor, filename.get(), encoding.get(), -1, NULL);
TEST_ASSERT_MSG (doc != NULL,
"file %s, encoding %s",
TEST_FMT_STR (filename),
TEST_FMT_STR (encoding));
TEST_FMT_STR (filename.get()),
TEST_FMT_STR (encoding.get()));
if (doc)
{
MooSaveInfo *info = moo_save_info_new (filename2, NULL);
MooSaveInfo *info = moo_save_info_new (filename2.get(), NULL);
TEST_ASSERT (moo_edit_save_as (doc, info, NULL));
TEST_ASSERT_SAME_FILE_CONTENT (filename2, filename);
TEST_ASSERT_SAME_FILE_CONTENT (filename2.get(), filename.get());
TEST_ASSERT (moo_edit_close (doc));
g_object_unref (info);
}
#ifdef MOO_OS_WIN32
out:
#endif
g_free (encoding);
g_free (filename2);
g_free (filename);
}
static void
@ -185,10 +175,9 @@ test_encodings (void)
{
GDir *dir;
const char *name;
char *working_dir;
mgw_errno_t err;
dir = g_dir_open (test_data.encodings_dir, 0, NULL);
dir = g_dir_open (test_data.encodings_dir.get(), 0, NULL);
if (!dir)
{
@ -197,13 +186,12 @@ test_encodings (void)
return;
}
working_dir = g_build_filename (test_data.working_dir, "encodings", (char*)0);
_moo_mkdir_with_parents (working_dir, &err);
gstr working_dir = g::build_filename (test_data.working_dir, "encodings");
_moo_mkdir_with_parents (working_dir.get(), &err);
while ((name = g_dir_read_name (dir)))
test_encodings_1 (name, working_dir);
test_encodings_1 (name, working_dir.get());
g_free (working_dir);
g_dir_close (dir);
}
@ -231,16 +219,15 @@ test_suite_init (G_GNUC_UNUSED gpointer data)
test_data.working_dir = g_build_filename (moo_test_get_working_dir (),
"editor-work", (char*)0);
test_data.encodings_dir = g_build_filename (moo_test_get_data_dir (),
"encodings", (char*)0);
test_data.encodings_dir = g::build_filename (moo_test_get_data_dir (),
"encodings");
if (_moo_mkdir_with_parents (test_data.working_dir, &err) != 0)
if (_moo_mkdir_with_parents (test_data.working_dir.get(), &err) != 0)
{
g_critical ("could not create directory '%s': %s",
test_data.working_dir,
mgw_strerror (err));
g_free (test_data.working_dir);
test_data.working_dir = NULL;
test_data.working_dir.clear();
return FALSE;
}
@ -254,7 +241,7 @@ test_suite_cleanup (G_GNUC_UNUSED gpointer data)
MooEditor *editor;
GError *error = NULL;
if (!_moo_remove_dir (test_data.working_dir, TRUE, &error))
if (!_moo_remove_dir (test_data.working_dir.get(), TRUE, &error))
{
g_critical ("could not remove directory '%s': %s",
test_data.working_dir, error->message);
@ -262,8 +249,6 @@ test_suite_cleanup (G_GNUC_UNUSED gpointer data)
error = NULL;
}
g_free (test_data.working_dir);
g_free (test_data.encodings_dir);
test_data.working_dir = NULL;
test_data.encodings_dir = NULL;
@ -289,7 +274,7 @@ test_suite_cleanup (G_GNUC_UNUSED gpointer data)
void
moo_test_editor (void)
{
MooTestSuite *suite = moo_test_suite_new ("Editor",
MooTestSuite& suite = moo_test_suite_new ("Editor",
"Editor tests",
test_suite_init,
test_suite_cleanup,

View File

@ -62,7 +62,7 @@ moo_test_run_lua_file (const char *basename)
char *contents;
char *filename;
filename = g_build_filename (moo_test_get_data_dir (), "test-lua", basename, (char*) NULL);
filename = g_build_filename (moo_test_get_data_dir ().get(), "test-lua", basename, (char*) NULL);
if ((contents = moo_test_load_data_file (filename)))
{
@ -72,7 +72,7 @@ moo_test_run_lua_file (const char *basename)
g_assert (lua_gettop (L) == 0);
{
char *testdir = g_build_filename (moo_test_get_data_dir (), "test-lua", "lua", (char*) NULL);
char *testdir = g_build_filename (moo_test_get_data_dir ().get(), "test-lua", "lua", (char*) NULL);
lua_addpath (L, (char**) &testdir, 1);
g_free (testdir);
}
@ -115,14 +115,13 @@ void
moo_test_lua (MooTestOptions opts)
{
MooLuaTestData *data;
MooTestSuite *suite;
char **p;
if (!(opts & MOO_TEST_INSTALLED))
return;
data = moo_lua_test_data_new ();
suite = moo_test_suite_new ("MooLua", "Lua scripting tests", NULL, moo_lua_test_data_free, data);
MooTestSuite& suite = moo_test_suite_new("MooLua", "Lua scripting tests", NULL, moo_lua_test_data_free, data);
data->files = moo_test_list_data_files ("test-lua");

View File

@ -5,14 +5,12 @@
static void
moo_test_run_python_file (const char *basename)
{
char *filename = moo_test_find_data_file (basename);
gstr filename = moo_test_find_data_file (basename);
if (!filename)
if (filename.empty())
TEST_FAILED_MSG ("could not find file `%s'", basename);
else if (!medit_python_run_file (filename, TRUE))
else if (!medit_python_run_file (filename.get(), TRUE))
TEST_FAILED_MSG ("error running file `%s'", basename);
g_free (filename);
}
static void
@ -24,7 +22,7 @@ test_func (MooTestEnv *env)
{
char *dir;
been_here = TRUE;
dir = g_build_filename (moo_test_get_data_dir (), "test-python", NULL);
dir = g_build_filename (moo_test_get_data_dir ().get(), "test-python", NULL);
moo_python_add_path (dir);
g_free (dir);
}
@ -33,7 +31,7 @@ test_func (MooTestEnv *env)
}
static void
add_test (MooTestSuite *suite, const char *name, const char *description, const char *python_file)
add_test (MooTestSuite &suite, const char *name, const char *description, const char *python_file)
{
moo_test_suite_add_test (suite, name, description, test_func, (void*) python_file);
}
@ -43,9 +41,7 @@ moo_test_python (void)
{
if (moo_python_enabled ())
{
MooTestSuite *suite;
suite = moo_test_suite_new ("MooPython", "Python scripting tests", NULL, NULL, NULL);
MooTestSuite& suite = moo_test_suite_new ("MooPython", "Python scripting tests", NULL, NULL, NULL);
add_test (suite, "moo", "test of moo module", "test-python/testmoo.py");
}

View File

@ -52,9 +52,9 @@ endif()
list(APPEND built_moopython_sources moopython/pygtk/moo.defs)
add_custom_command(OUTPUT moopython/pygtk/moo.defs
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/getoutput.py moopython/pygtk/moo.defs
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/getoutput.py moopython/pygtk/moo.defs
${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/api/gendefs.py ${CMAKE_SOURCE_DIR}/api/moo.xml
DEPENDS ${gendefs_files} ${CMAKE_SOURCE_DIR}/api/moo.xml)
DEPENDS ${gendefs_files} ${CMAKE_SOURCE_DIR}/api/moo.xml)
set(codegen_files
moopython/codegen/codegen.py
@ -149,7 +149,7 @@ list(APPEND moopython_sources
moopython/moopython-utils.h
moopython/moopython-utils.c
moopython/moopython-tests.h
moopython/moopython-tests.c
moopython/moopython-tests.cpp
)
list(APPEND moopython_sources

View File

@ -16,36 +16,51 @@
#include "moo-test-macros.h"
#include "mooutils/mooutils-fs.h"
#include "mooutils/mooutils-messages.h"
#include "moocpp/gstr.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
typedef struct {
char *text;
char *file;
struct TestAssertInfo
{
gstr text;
gstr file;
int line;
} TestAssertInfo;
typedef struct {
char *name;
char *description;
TestAssertInfo(const char* text,
const char* file,
int line)
: text(text)
, file(file)
, line(line)
{
}
};
struct MooTest
{
gstr name;
gstr description;
MooTestFunc func;
gpointer data;
GSList *failed_asserts;
} MooTest;
std::vector<TestAssertInfo> failed_asserts;
};
struct MooTestSuite {
char *name;
char *description;
GSList *tests;
struct MooTestSuite
{
gstr name;
gstr description;
std::vector<MooTest> tests;
MooTestSuiteInit init_func;
MooTestSuiteCleanup cleanup_func;
gpointer data;
};
typedef struct {
char *data_dir;
GSList *test_suites;
struct MooTestRegistry
{
gstr data_dir;
std::vector<MooTestSuite> test_suites;
MooTestSuite *current_suite;
MooTest *current_test;
struct TestRun {
@ -56,148 +71,88 @@ typedef struct {
guint tests_passed;
guint asserts_passed;
} tr;
} MooTestRegistry;
};
static MooTestRegistry registry;
static TestAssertInfo *
test_assert_info_new (const char *text,
const char *file,
int line)
MooTestSuite&
moo_test_suite_new(const char *name,
const char *description,
MooTestSuiteInit init_func,
MooTestSuiteCleanup cleanup_func,
gpointer data)
{
TestAssertInfo *ai = g_new0 (TestAssertInfo, 1);
ai->file = g_strdup (file);
ai->text = g_strdup (text);
ai->line = line;
return ai;
}
MooTestSuite ts;
ts.name = name;
ts.description = description;
ts.init_func = init_func;
ts.cleanup_func = cleanup_func;
ts.data = data;
static void
test_assert_info_free (TestAssertInfo *ai)
{
if (ai)
{
g_free (ai->file);
g_free (ai->text);
g_free (ai);
}
}
MooTestSuite *
moo_test_suite_new (const char *name,
const char *description,
MooTestSuiteInit init_func,
MooTestSuiteCleanup cleanup_func,
gpointer data)
{
MooTestSuite *ts;
g_return_val_if_fail (name != NULL, NULL);
ts = g_new0 (MooTestSuite, 1);
ts->name = g_strdup (name);
ts->description = g_strdup (description);
ts->init_func = init_func;
ts->cleanup_func = cleanup_func;
ts->data = data;
ts->tests = NULL;
registry.test_suites = g_slist_append (registry.test_suites, ts);
return ts;
registry.test_suites.push_back(std::move(ts));
return registry.test_suites.back();
}
void
moo_test_suite_add_test (MooTestSuite *ts,
const char *name,
const char *description,
MooTestFunc test_func,
gpointer data)
moo_test_suite_add_test(MooTestSuite &ts,
const char *name,
const char *description,
MooTestFunc test_func,
gpointer data)
{
MooTest *test;
g_return_if_fail(name != NULL);
g_return_if_fail(test_func != NULL);
g_return_if_fail (ts != NULL);
g_return_if_fail (name != NULL);
g_return_if_fail (test_func != NULL);
MooTest test;
test.name = name;
test.description = description;
test.func = test_func;
test.data = data;
test = g_new0 (MooTest, 1);
test->name = g_strdup (name);
test->description = g_strdup (description);
test->func = test_func;
test->data = data;
ts->tests = g_slist_append (ts->tests, test);
}
static void
moo_test_suite_free (MooTestSuite *ts)
{
if (ts)
{
GSList *l;
for (l = ts->tests; l != NULL; l = l->next)
{
MooTest *test = l->data;
g_slist_foreach (test->failed_asserts,
(GFunc) test_assert_info_free,
NULL);
g_slist_free (test->failed_asserts);
g_free (test->description);
g_free (test->name);
g_free (test);
}
g_slist_free (ts->tests);
g_free (ts->description);
g_free (ts->name);
g_free (ts);
}
ts.tests.push_back(std::move(test));
}
static gboolean
run_test (MooTest *test,
MooTestSuite *ts,
MooTestOptions opts)
run_test(MooTest &test,
MooTestSuite &ts,
MooTestOptions opts)
{
MooTestEnv env;
gboolean failed;
if (opts & MOO_TEST_LIST_ONLY)
{
fprintf (stdout, " Test: %s - %s\n", test->name, test->description);
fprintf (stdout, " Test: %s - %s\n", test.name.get(), test.description.get());
return TRUE;
}
env.suite_data = ts->data;
env.test_data = test->data;
MooTestEnv env;
env.suite_data = ts.data;
env.test_data = test.data;
fprintf (stdout, " Test: %s ... ", test->name);
fflush (stdout);
fprintf(stdout, " Test: %s ... ", test.name.get());
fflush(stdout);
registry.current_test = test;
test->func (&env);
registry.current_test = &test;
test.func(&env);
registry.current_test = NULL;
failed = test->failed_asserts != NULL;
failed = !test.failed_asserts.empty();
if (failed)
fprintf (stdout, "FAILED\n");
else
fprintf (stdout, "passed\n");
if (test->failed_asserts)
if (!test.failed_asserts.empty())
{
GSList *l;
int count;
test->failed_asserts = g_slist_reverse (test->failed_asserts);
for (l = test->failed_asserts, count = 1; l != NULL; l = l->next, count++)
int count = 1;
for (const auto& ai: test.failed_asserts)
{
TestAssertInfo *ai = l->data;
fprintf (stdout, " %d. %s", count, ai->file ? ai->file : "<unknown>");
if (ai->line > -1)
fprintf (stdout, ":%d", ai->line);
fprintf (stdout, " - %s\n", ai->text ? ai->text : "FAILED");
fprintf (stdout, " %d. %s", count, !ai.file.empty() ? ai.file.get() : "<unknown>");
if (ai.line > -1)
fprintf (stdout, ":%d", ai.line);
fprintf (stdout, " - %s\n", !ai.text.empty() ? ai.text.get() : "FAILED");
++count;
}
}
@ -209,29 +164,32 @@ run_test (MooTest *test,
}
static void
run_suite (MooTestSuite *ts,
run_suite (MooTestSuite &ts,
MooTest *single_test,
MooTestOptions opts)
{
GSList *l;
gboolean run = !(opts & MOO_TEST_LIST_ONLY);
gboolean passed = TRUE;
if (run && ts->init_func && !ts->init_func (ts->data))
if (run && ts.init_func && !ts.init_func(ts.data))
return;
registry.current_suite = ts;
registry.current_suite = &ts;
g_print ("Suite: %s\n", ts->name);
g_print ("Suite: %s\n", ts.name.get());
if (single_test)
passed = run_test (single_test, ts, opts) && passed;
{
passed = run_test(*single_test, ts, opts) && passed;
}
else
for (l = ts->tests; l != NULL; l = l->next)
passed = run_test (l->data, ts, opts) && passed;
{
for (auto& t: ts.tests)
passed = run_test(t, ts, opts) && passed;
}
if (run && ts->cleanup_func)
ts->cleanup_func (ts->data);
if (run && ts.cleanup_func)
ts.cleanup_func(ts.data);
registry.current_suite = NULL;
registry.tr.suites += 1;
@ -240,58 +198,45 @@ run_suite (MooTestSuite *ts,
}
static gboolean
find_test (const char *name,
find_test (const gstr& name,
MooTestSuite **ts_p,
MooTest **test_p)
{
GSList *l;
char **pieces;
const char *suite_name = NULL;
const char *test_name = NULL;
gboolean retval = FALSE;
*ts_p = nullptr;
*test_p = nullptr;
g_return_val_if_fail (name != NULL, FALSE);
std::vector<gstr> pieces = name.split("/", 2);
g_return_val_if_fail (!pieces.empty(), FALSE);
pieces = g_strsplit (name, "/", 2);
g_return_val_if_fail (pieces != NULL && pieces[0] != NULL, FALSE);
const gstr& suite_name = pieces[0];
const gstr& test_name = pieces.size() > 1 ? pieces[1] : gstr();
suite_name = pieces[0];
test_name = pieces[1];
for (l = registry.test_suites; l != NULL; l = l->next)
for (auto& ts: registry.test_suites)
{
MooTestSuite *ts = l->data;
GSList *tl;
if (strcmp (ts->name, suite_name) != 0)
continue;
if (!test_name)
if (ts.name == suite_name)
{
*ts_p = ts;
*test_p = NULL;
retval = TRUE;
goto out;
}
for (tl = ts->tests; tl != NULL; tl = tl->next)
{
MooTest *test = tl->data;
if (strcmp (test->name, test_name) == 0)
if (test_name.empty())
{
*ts_p = ts;
*test_p = test;
retval = TRUE;
goto out;
*ts_p = &ts;
*test_p = NULL;
return true;
}
}
break;
for (auto& test : ts.tests)
{
if (test.name == test_name)
{
*ts_p = &ts;
*test_p = &test;
return true;
}
}
break;
}
}
out:
g_strfreev (pieces);
return retval;
return false;
}
gboolean
@ -318,14 +263,13 @@ moo_test_run_tests (char **tests,
exit (EXIT_FAILURE);
}
run_suite (single_ts, single_test, opts);
run_suite (*single_ts, single_test, opts);
}
}
else
{
GSList *l;
for (l = registry.test_suites; l != NULL; l = l->next)
run_suite (l->data, NULL, opts);
for (auto& ts: registry.test_suites)
run_suite(ts, nullptr, opts);
}
fprintf (stdout, "\n");
@ -354,14 +298,10 @@ moo_test_run_tests (char **tests,
void
moo_test_cleanup (void)
{
GSList *l;
GError *error = NULL;
for (l = registry.test_suites; l != NULL; l = l->next)
moo_test_suite_free (l->data);
g_free (registry.data_dir);
registry.data_dir = NULL;
registry.test_suites.clear();
registry.data_dir.clear();
if (g_file_test (moo_test_get_working_dir (), G_FILE_TEST_IS_DIR) &&
!_moo_remove_dir (moo_test_get_working_dir (), TRUE, &error))
@ -399,9 +339,7 @@ moo_test_assert_impl (gboolean passed,
if (passed)
registry.tr.asserts_passed += 1;
else
registry.current_test->failed_asserts =
g_slist_prepend (registry.current_test->failed_asserts,
test_assert_info_new (text, file, line));
registry.current_test->failed_asserts.push_back(TestAssertInfo(text, file, line));
}
void
@ -435,7 +373,7 @@ moo_test_assert_msg (gboolean passed,
}
const char *
const gstr&
moo_test_get_data_dir (void)
{
return registry.data_dir;
@ -444,8 +382,6 @@ moo_test_get_data_dir (void)
void
moo_test_set_data_dir (const char *dir)
{
char *tmp;
g_return_if_fail (dir != NULL);
if (!g_file_test (dir, G_FILE_TEST_IS_DIR))
@ -454,9 +390,7 @@ moo_test_set_data_dir (const char *dir)
return;
}
tmp = registry.data_dir;
registry.data_dir = _moo_normalize_file_path (dir);
g_free (tmp);
registry.data_dir.steal(_moo_normalize_file_path(dir));
}
const char *
@ -465,35 +399,31 @@ moo_test_get_working_dir (void)
return "test-working-dir";
}
char *
gstr
moo_test_find_data_file (const char *basename)
{
char *fullname;
g_return_val_if_fail(!registry.data_dir.empty(), gstr());
g_return_val_if_fail (registry.data_dir != NULL, NULL);
if (!_moo_path_is_absolute (basename))
fullname = g_build_filename (registry.data_dir, basename, NULL);
if (!_moo_path_is_absolute(basename))
return gstr::take(g_build_filename(registry.data_dir.get(), basename, NULL));
else
fullname = g_strdup (basename);
return fullname;
return basename;
}
char **
moo_test_list_data_files (const char *dir)
{
GDir *gdir;
char *freeme = NULL;
gstr tmp;
GError *error = NULL;
const char *name;
GPtrArray *names = NULL;
if (!_moo_path_is_absolute (dir))
{
g_return_val_if_fail (registry.data_dir != NULL, NULL);
freeme = g_build_filename (registry.data_dir, dir, NULL);
dir = freeme;
g_return_val_if_fail (registry.data_dir != nullptr, NULL);
tmp.steal(g_build_filename(registry.data_dir.get(), dir, NULL));
dir = tmp.get();
}
if (!(gdir = g_dir_open (dir, 0, &error)))
@ -512,7 +442,6 @@ moo_test_list_data_files (const char *dir)
if (gdir)
g_dir_close (gdir);
g_free (freeme);
return (char**) g_ptr_array_free (names, FALSE);
}
@ -523,10 +452,10 @@ moo_test_load_data_file (const char *basename)
char *contents = NULL;
GError *error = NULL;
g_return_val_if_fail (registry.data_dir != NULL, NULL);
g_return_val_if_fail (registry.data_dir != nullptr, NULL);
if (!_moo_path_is_absolute (basename))
fullname = g_build_filename (registry.data_dir, basename, NULL);
fullname = g_build_filename (registry.data_dir.get(), basename, NULL);
else
fullname = g_strdup (basename);
@ -560,7 +489,7 @@ add_func (gpointer key,
G_GNUC_UNUSED gpointer value,
GString *string)
{
g_string_append (string, key);
g_string_append (string, (const char*) key);
g_string_append (string, "\n");
}

View File

@ -13,22 +13,20 @@
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MOO_TEST_UTILS_H
#define MOO_TEST_UTILS_H
#pragma once
#include <mooglib/moo-glib.h>
#include <string.h>
#include <stdarg.h>
#include <mooutils/mooutils-macros.h>
#include <mooutils/mooutils-misc.h>
#include <moocpp/gstr.h>
G_BEGIN_DECLS
typedef struct {
struct MooTestEnv
{
gpointer suite_data;
gpointer test_data;
} MooTestEnv;
};
typedef enum {
MOO_TEST_LIST_ONLY = 1 << 0,
@ -41,12 +39,12 @@ typedef gboolean (*MooTestSuiteInit) (gpointer data);
typedef void (*MooTestSuiteCleanup) (gpointer data);
typedef void (*MooTestFunc) (MooTestEnv *env);
MooTestSuite *moo_test_suite_new (const char *name,
MooTestSuite &moo_test_suite_new (const char *name,
const char *description,
MooTestSuiteInit init_func,
MooTestSuiteCleanup cleanup_func,
gpointer data);
void moo_test_suite_add_test (MooTestSuite *ts,
void moo_test_suite_add_test (MooTestSuite &ts,
const char *name,
const char *description,
MooTestFunc test_func,
@ -74,9 +72,9 @@ void moo_test_assert_msg (gboolean passed,
...) G_GNUC_PRINTF(4, 5);
char *moo_test_load_data_file (const char *basename);
char *moo_test_find_data_file (const char *basename);
gstr moo_test_find_data_file (const char *basename);
void moo_test_set_data_dir (const char *dir);
const char *moo_test_get_data_dir (void);
const gstr& moo_test_get_data_dir (void);
const char *moo_test_get_working_dir (void);
char **moo_test_list_data_files (const char *subdir);
@ -86,8 +84,3 @@ void moo_test_coverage_record (const char *lang,
const char *function);
gboolean moo_test_set_silent_messages (gboolean silent);
G_END_DECLS
#endif /* MOO_TEST_UTILS_H */

View File

@ -448,7 +448,7 @@ moo_keymap_translate_keyboard_state (GdkKeymap *keymap,
GdkModifierType *consumed_modifiers_p)
{
guint keyval = 0;
GdkModifierType consumed_modifiers = 0;
GdkModifierType consumed_modifiers = (GdkModifierType) 0;
gboolean retval =
gdk_keymap_translate_keyboard_state (keymap, hardware_keycode, state, group,
&keyval, effective_group, level,
@ -458,7 +458,7 @@ moo_keymap_translate_keyboard_state (GdkKeymap *keymap,
if ((state & GDK_SHIFT_MASK) && (consumed_modifiers & GDK_SHIFT_MASK) &&
need_workaround_for_671562 (keyval))
{
consumed_modifiers &= ~GDK_SHIFT_MASK;
consumed_modifiers = (GdkModifierType) (consumed_modifiers & ~GDK_SHIFT_MASK);
}
if (keyval_p)
@ -724,9 +724,9 @@ _moo_accel_parse (const char *accel,
goto out;
}
if ((p = strchr (accel, '+')) && p != accel + len - 1)
if ((p = (char*) strchr (accel, '+')) && p != accel + len - 1)
return accel_parse_sep (accel, "+", keyval, modifiers);
else if ((p = strchr (accel, '-')) && p != accel + len - 1)
else if ((p = (char*) strchr (accel, '-')) && p != accel + len - 1)
return accel_parse_sep (accel, "-", keyval, modifiers);
key = parse_key (accel);
@ -1009,7 +1009,7 @@ delete_prefs_keys (void)
GSList *keys = moo_prefs_list_keys (MOO_PREFS_RC);
while (keys)
{
char *key = keys->data;
char *key = (char*) keys->data;
if (g_str_has_prefix (key, "Shortcuts/Foobar/"))
moo_prefs_delete_key (key);
@ -1035,7 +1035,7 @@ test_suite_cleanup (void)
void
moo_test_mooaccel (void)
{
MooTestSuite *suite = moo_test_suite_new ("mooaccel", "mooutils/mooaccel.c",
MooTestSuite& suite = moo_test_suite_new ("mooaccel", "mooutils/mooaccel.c",
(MooTestSuiteInit) test_suite_init,
(MooTestSuiteCleanup) test_suite_cleanup,
NULL);

View File

@ -100,7 +100,7 @@ moo_file_reader_new_real (const char *filename,
return NULL;
}
reader = g_object_new (MOO_TYPE_FILE_READER, (const char*) NULL);
reader = MOO_FILE_READER (g_object_new (MOO_TYPE_FILE_READER, (const char*) NULL));
reader->file = file;
return reader;
@ -304,7 +304,7 @@ moo_local_file_writer_new (GFile *file,
if (!stream)
goto error;
writer = g_object_new (MOO_TYPE_LOCAL_FILE_WRITER, (const char*) NULL);
writer = (MooLocalFileWriter*) g_object_new (MOO_TYPE_LOCAL_FILE_WRITER, (const char*) NULL);
writer->file = file_copy;
writer->stream = G_OUTPUT_STREAM (stream);
writer->flags = flags;
@ -357,9 +357,9 @@ moo_config_writer_new (const char *filename,
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (!error || !*error, NULL);
flags = MOO_FILE_WRITER_CONFIG_MODE | MOO_FILE_WRITER_TEXT_MODE;
flags = (MooFileWriterFlags) (MOO_FILE_WRITER_CONFIG_MODE | MOO_FILE_WRITER_TEXT_MODE);
if (save_backup)
flags |= MOO_FILE_WRITER_SAVE_BACKUP;
flags = (MooFileWriterFlags) (flags | MOO_FILE_WRITER_SAVE_BACKUP);
return moo_file_writer_new (filename, flags, error);
}
@ -556,7 +556,7 @@ moo_string_writer_init (MooStringWriter *writer)
MooFileWriter *
moo_string_writer_new (void)
{
return g_object_new (MOO_TYPE_STRING_WRITER, (const char*) NULL);
return (MooFileWriter*) g_object_new (MOO_TYPE_STRING_WRITER, (const char*) NULL);
}
const char *
@ -717,9 +717,7 @@ test_moo_file_writer (void)
void
moo_test_moo_file_writer (void)
{
MooTestSuite *suite;
suite = moo_test_suite_new ("MooFileWriter", "MooFileWriter tests", NULL, NULL, NULL);
MooTestSuite& suite = moo_test_suite_new ("MooFileWriter", "MooFileWriter tests", NULL, NULL, NULL);
moo_test_suite_add_test (suite, "MooFileWriter", "MooFileWriter tests",
(MooTestFunc) test_moo_file_writer, NULL);

View File

@ -187,9 +187,7 @@ moo_test_i18n (MooTestOptions opts)
{
if (opts & MOO_TEST_INSTALLED)
{
MooTestSuite *suite;
suite = moo_test_suite_new ("mooi18n", "mooutils/mooi18n.c", NULL, NULL, NULL);
MooTestSuite& suite = moo_test_suite_new ("mooi18n", "mooutils/mooi18n.c", NULL, NULL, NULL);
moo_test_suite_add_test (suite, "mooi18n", "test of mooi18n",
(MooTestFunc) test_mooi18n, NULL);

View File

@ -127,7 +127,7 @@ filename_list_to_double_null_terminated_string (GList *filenames)
long len;
gunichar2 *wstr;
wstr = g_utf8_to_utf16 (filenames->data, -1, NULL, &len, NULL);
wstr = g_utf8_to_utf16 ((const char*) filenames->data, -1, NULL, &len, NULL);
filenames = filenames->next;
if (!wstr)
@ -167,7 +167,7 @@ move_or_copy_files_ui (GList *filenames,
return FALSE;
}
shop.hwnd = parent && parent->window ? GDK_WINDOW_HWND (parent->window) : NULL;
shop.hwnd = parent && parent->window ? (HWND) GDK_WINDOW_HWND (parent->window) : NULL;
shop.wFunc = copy ? FO_COPY : FO_MOVE;
shop.pFrom = from;
shop.pTo = to;
@ -997,7 +997,7 @@ test_normalize_file_path (void)
for (i = 0; i < paths->len; i += 2)
{
test_normalize_path_one (paths->pdata[i], paths->pdata[i+1],
test_normalize_path_one ((const char*) paths->pdata[i], (const char*) paths->pdata[i+1],
_moo_normalize_file_path,
"_moo_normalize_file_path");
g_free (paths->pdata[i]);
@ -1032,9 +1032,7 @@ test_normalize_file_path_win32 (void)
void
moo_test_mooutils_fs (void)
{
MooTestSuite *suite;
suite = moo_test_suite_new ("mooutils-fs", "mooutils/mooutils-fs.c", NULL, NULL, NULL);
MooTestSuite& suite = moo_test_suite_new ("mooutils-fs", "mooutils/mooutils-fs.c", NULL, NULL, NULL);
moo_test_suite_add_test (suite, "_moo_normalize_file_path", "test of _moo_normalize_file_path()",
(MooTestFunc) test_normalize_file_path, NULL);
@ -1173,7 +1171,7 @@ _moo_glob_new (const char *pattern)
MooGlob *gl;
GRegex *re;
char *re_pattern;
GRegexCompileFlags flags = 0;
GRegexCompileFlags flags = (GRegexCompileFlags) 0;
GError *error = NULL;
g_return_val_if_fail (pattern != NULL, NULL);
@ -1185,7 +1183,7 @@ _moo_glob_new (const char *pattern)
if (!(re_pattern = glob_to_re (pattern)))
return NULL;
re = g_regex_new (re_pattern, flags, 0, &error);
re = g_regex_new (re_pattern, flags, (GRegexMatchFlags) 0, &error);
g_free (re_pattern);
@ -1211,7 +1209,7 @@ _moo_glob_match (MooGlob *glob,
g_return_val_if_fail (filename_utf8 != NULL, FALSE);
g_return_val_if_fail (g_utf8_validate (filename_utf8, -1, NULL), FALSE);
return g_regex_match (glob->re, filename_utf8, 0, NULL);
return g_regex_match (glob->re, filename_utf8, (GRegexMatchFlags) 0, NULL);
}
#endif

View File

@ -60,7 +60,7 @@ moo_gtype_lcopy_value (const GValue *value,
GTypeCValue *collect_values,
G_GNUC_UNUSED guint collect_flags)
{
GType *ptr = collect_values->v_pointer;
GType *ptr = (GType*) collect_values->v_pointer;
*ptr = _moo_value_get_gtype (value);
return NULL;
}
@ -99,11 +99,11 @@ _moo_gtype_get_type (void)
&val_table
};
static GTypeFundamentalInfo finfo = { 0 };
static GTypeFundamentalInfo finfo = { (GTypeFundamentalFlags) 0 };
type = g_type_register_fundamental (g_type_fundamental_next (),
"MooGType",
&info, &finfo, 0);
&info, &finfo, (GTypeFlags) 0);
}
return type;
@ -189,7 +189,7 @@ _moo_param_gtype_get_type (void)
param_gtype_cmp, /* values_cmp */
};
info.value_type = MOO_TYPE_GTYPE;
info.value_type = MOO_TYPE_GTYPE;
type = g_param_type_register_static ("MooParamGType", &info);
}
@ -432,7 +432,7 @@ _moo_value_convert (const GValue *src,
if (src_type == GDK_TYPE_COLOR)
{
char string[14];
const GdkColor *color = g_value_get_boxed (src);
const GdkColor *color = (const GdkColor*) g_value_get_boxed (src);
if (!color)
{
@ -677,8 +677,8 @@ _moo_value_equal (const GValue *a,
{
const GdkColor *ca, *cb;
ca = g_value_get_boxed (a);
cb = g_value_get_boxed (b);
ca = (const GdkColor*) g_value_get_boxed (a);
cb = (const GdkColor*) g_value_get_boxed (b);
if (!ca || !cb)
return ca == cb;
@ -1180,9 +1180,7 @@ test_misc (void)
void
moo_test_gobject (void)
{
MooTestSuite *suite;
suite = moo_test_suite_new ("mooutils-gobject", "mooutils/mooutils-gobject.c", NULL, NULL, NULL);
MooTestSuite& suite = moo_test_suite_new ("mooutils-gobject", "mooutils/mooutils-gobject.c", NULL, NULL, NULL);
moo_test_suite_add_test (suite, "convert", "test of converting values", (MooTestFunc) test_misc, NULL);
}
@ -1573,9 +1571,9 @@ watch_alloc (gsize size,
g_return_val_if_fail (G_IS_OBJECT (source), NULL);
g_return_val_if_fail (G_IS_OBJECT (target), NULL);
w = g_malloc0 (size);
w->source = _moo_object_ptr_new (source, (GWeakNotify) watch_source_died, w);
w->target = _moo_object_ptr_new (target, (GWeakNotify) watch_target_died, w);
w = (Watch*) g_malloc0 (size);
w->source = _moo_object_ptr_new (G_OBJECT (source), (GWeakNotify) watch_source_died, w);
w->target = _moo_object_ptr_new (G_OBJECT (target), (GWeakNotify) watch_target_died, w);
w->klass = klass;
w->notify = notify;
w->notify_data = notify_data;
@ -1628,8 +1626,8 @@ prop_watch_new (GObject *target,
g_return_val_if_fail (source_prop != NULL, NULL);
g_return_val_if_fail (transform != NULL, NULL);
target_class = g_type_class_peek (G_OBJECT_TYPE (target));
source_class = g_type_class_peek (G_OBJECT_TYPE (source));
target_class = (GObjectClass*) g_type_class_peek (G_OBJECT_TYPE (target));
source_class = (GObjectClass*) g_type_class_peek (G_OBJECT_TYPE (source));
source_pspec = g_object_class_find_property (source_class, source_prop);
target_pspec = g_object_class_find_property (target_class, target_prop);
@ -1695,7 +1693,8 @@ _moo_add_property_watch (gpointer target,
g_return_val_if_fail (source_prop != NULL, 0);
g_return_val_if_fail (transform != NULL, 0);
watch = prop_watch_new (target, target_prop, source, source_prop,
watch = prop_watch_new (G_OBJECT (target), target_prop,
G_OBJECT (source), source_prop,
NULL, transform, transform_data,
destroy_notify, transform_data);
@ -2228,7 +2227,7 @@ _moo_data_get_value (MooData *data,
g_return_val_if_fail (data != NULL, FALSE);
g_return_val_if_fail (!dest || dest->g_type == 0, FALSE);
value = g_hash_table_lookup (data->hash, key);
value = (GValue*) g_hash_table_lookup (data->hash, key);
if (value && dest)
{
@ -2249,12 +2248,12 @@ _moo_data_get_ptr (MooData *data,
g_return_val_if_fail (data != NULL, NULL);
value = g_hash_table_lookup (data->hash, key);
value = (GValue*) g_hash_table_lookup (data->hash, key);
if (value)
{
g_return_val_if_fail (G_VALUE_TYPE (value) == MOO_TYPE_PTR, NULL);
ptr = g_value_get_boxed (value);
ptr = (MooPtr*) g_value_get_boxed (value);
return ptr->data;
}
else

View File

@ -2275,9 +2275,7 @@ test_types (void)
void
moo_test_mooutils_misc (void)
{
MooTestSuite *suite;
suite = moo_test_suite_new ("mooutils-misc", "mooutils/mooutils-misc.c", NULL, NULL, NULL);
MooTestSuite& suite = moo_test_suite_new ("mooutils-misc", "mooutils/mooutils-misc.c", NULL, NULL, NULL);
moo_test_suite_add_test (suite, "moo_splitlines", "test of moo_splitlines()",
(MooTestFunc) test_moo_splitlines, NULL);

View File

@ -201,7 +201,7 @@ moo_win32_get_dll_dir (const char *dll)
{
GError *error = NULL;
dll_utf16 = g_utf8_to_utf16 (dll, -1, NULL, NULL, &error);
dll_utf16 = (wchar_t*) g_utf8_to_utf16 (dll, -1, NULL, NULL, &error);
if (!dll_utf16)
{
@ -216,7 +216,7 @@ moo_win32_get_dll_dir (const char *dll)
g_return_val_if_fail (handle != NULL, g_strdup ("."));
if (GetModuleFileNameW (handle, buf, G_N_ELEMENTS (buf)) > 0)
dllname = g_utf16_to_utf8 (buf, -1, NULL, NULL, NULL);
dllname = g_utf16_to_utf8 ((const gunichar2*) buf, -1, NULL, NULL, NULL);
if (dllname)
dir = g_path_get_dirname (dllname);
@ -297,12 +297,12 @@ _moo_win32_message_box(GtkWidget *parent,
if (parent)
parent = gtk_widget_get_toplevel (parent);
if (parent)
parenthwnd = GDK_WINDOW_HWND (parent->window);
parenthwnd = (HWND) GDK_WINDOW_HWND (parent->window);
if (title)
wtitle = g_utf8_to_utf16 (title, -1, NULL, NULL, NULL);
wtitle = (wchar_t*) g_utf8_to_utf16 (title, -1, NULL, NULL, NULL);
if (text)
wtext = g_utf8_to_utf16 (text, -1, NULL, NULL, NULL);
wtext = (wchar_t*) g_utf8_to_utf16 (text, -1, NULL, NULL, NULL);
ret = MessageBox(parenthwnd, wtext, wtitle, type);
@ -362,7 +362,7 @@ _moo_win32_gettimeofday (struct timeval *tp,
#endif /* MOO_NEED_GETTIMEOFDAY */
int
extern "C" int
_moo_win32_fnmatch (const char *pattern,
const char *string,
int flags)
@ -432,9 +432,7 @@ test_moo_win32_lame_parse_cmd_line (void)
void
moo_test_mooutils_win32 (void)
{
MooTestSuite *suite;
suite = moo_test_suite_new ("mooutils-win32", "win32 utility functions", NULL, NULL, NULL);
MooTestSuite& suite = moo_test_suite_new ("mooutils-win32", "win32 utility functions", NULL, NULL, NULL);
moo_test_suite_add_test (suite, "_moo_win32_lame_parse_cmd_line", "test of _moo_win32_lame_parse_cmd_line()",
(MooTestFunc) test_moo_win32_lame_parse_cmd_line,
NULL);

View File

@ -1,140 +1,140 @@
SET(moo_utils_enum_headers
mooutils/moodialogs.h
mooutils/moofiledialog.h
mooutils/moouixml.h
mooutils/moowindow.h
mooutils/moodialogs.h
mooutils/moofiledialog.h
mooutils/moouixml.h
mooutils/moowindow.h
)
SET(mooutils_sources
mooutils/mooutils.cmake
${moo_utils_enum_headers}
mooutils/mooarray.h
mooutils/mooutils-cpp.h
mooutils/mooutils-thread.cpp
mooutils/mooutils-thread.h
mooutils/moohistorymgr.c
mooutils/moohistorymgr.h
mooutils/moo-environ.h
mooutils/mooaccel.c
mooutils/mooaccel.h
mooutils/mooaccelbutton.c
mooutils/mooaccelbutton.h
mooutils/mooaccelprefs.c
mooutils/mooaccelprefs.h
mooutils/mooaction-private.h
mooutils/mooaction.c
mooutils/mooaction.h
mooutils/mooactionbase-private.h
mooutils/mooactionbase.c
mooutils/mooactionbase.h
mooutils/mooactioncollection.c
mooutils/mooactioncollection.h
mooutils/mooactionfactory.c
mooutils/mooactionfactory.h
mooutils/mooactiongroup.c
mooutils/mooactiongroup.h
mooutils/mooapp-ipc.c
mooutils/mooapp-ipc.h
mooutils/mooappinput-common.c
mooutils/mooappinput-priv.h
mooutils/mooappinput.h
mooutils/mooatom.h
mooutils/moobigpaned.c
mooutils/moobigpaned.h
mooutils/mooclosure.c
mooutils/mooclosure.h
mooutils/moocombo.c
mooutils/moocombo.h
mooutils/moocompat.h
mooutils/moodialogs.c
mooutils/mooeditops.c
mooutils/mooeditops.h
mooutils/mooencodings-data.h
mooutils/mooencodings.c
mooutils/mooencodings.h
mooutils/mooentry.cpp
mooutils/mooentry.h
mooutils/moofiledialog.c
mooutils/moofileicon.c
mooutils/moofileicon.h
mooutils/moofilewatch.c
mooutils/moofilewatch.h
mooutils/moofilewriter.c
mooutils/moofilewriter.h
mooutils/moofilewriter-private.h
mooutils/moofiltermgr.c
mooutils/moofiltermgr.h
mooutils/moofontsel.c
mooutils/moofontsel.h
mooutils/mooglade.c
mooutils/mooglade.h
mooutils/moohelp.c
mooutils/moohelp.h
mooutils/moohistorycombo.c
mooutils/moohistorycombo.h
mooutils/moohistorylist.c
mooutils/moohistorylist.h
mooutils/mooi18n.c
mooutils/mooi18n.h
mooutils/moolist.h
mooutils/moomarkup.c
mooutils/moomarkup.h
mooutils/moomenu.c
mooutils/moomenu.h
mooutils/moomenuaction.c
mooutils/moomenuaction.h
mooutils/moomenumgr.c
mooutils/moomenumgr.h
mooutils/moomenutoolbutton.c
mooutils/moomenutoolbutton.h
mooutils/moo-mime.c
mooutils/moo-mime.h
mooutils/moonotebook.c
mooutils/moonotebook.h
mooutils/mooonce.h
mooutils/moopane.c
mooutils/moopane.h
mooutils/moopaned.c
mooutils/moopaned.h
mooutils/mooprefs.c
mooutils/mooprefs.h
mooutils/mooprefsdialog.c
mooutils/mooprefsdialog.h
mooutils/mooprefspage.c
mooutils/mooprefspage.h
mooutils/moospawn.c
mooutils/moospawn.h
mooutils/moostock.c
mooutils/moostock.h
mooutils/mootype-macros.h
mooutils/moouixml.c
mooutils/mooundo.c
mooutils/mooundo.h
mooutils/mooutils.h
mooutils/mooutils-debug.h
mooutils/mooutils-enums.c
mooutils/mooutils-enums.h
mooutils/mooutils-file.c
mooutils/mooutils-file.h
mooutils/mooutils-fs.c
mooutils/mooutils-fs.h
mooutils/mooutils-gobject-private.h
mooutils/mooutils-gobject.c
mooutils/mooutils-gobject.h
mooutils/mooutils-macros.h
mooutils/mooutils-mem.h
mooutils/mooutils-messages.h
mooutils/mooutils-misc.cpp
mooutils/mooutils-misc.h
mooutils/mooutils-script.c
mooutils/mooutils-script.h
mooutils/mooutils-tests.h
mooutils/mooutils-treeview.c
mooutils/mooutils-treeview.h
mooutils/moowindow.c
mooutils/stock-file-24.h
mooutils/stock-file-selector-24.h
mooutils/stock-terminal-24.h
mooutils/mooutils.cmake
${moo_utils_enum_headers}
mooutils/mooarray.h
mooutils/mooutils-cpp.h
mooutils/mooutils-thread.cpp
mooutils/mooutils-thread.h
mooutils/moohistorymgr.c
mooutils/moohistorymgr.h
mooutils/moo-environ.h
mooutils/mooaccel.cpp
mooutils/mooaccel.h
mooutils/mooaccelbutton.c
mooutils/mooaccelbutton.h
mooutils/mooaccelprefs.c
mooutils/mooaccelprefs.h
mooutils/mooaction-private.h
mooutils/mooaction.c
mooutils/mooaction.h
mooutils/mooactionbase-private.h
mooutils/mooactionbase.c
mooutils/mooactionbase.h
mooutils/mooactioncollection.c
mooutils/mooactioncollection.h
mooutils/mooactionfactory.c
mooutils/mooactionfactory.h
mooutils/mooactiongroup.c
mooutils/mooactiongroup.h
mooutils/mooapp-ipc.c
mooutils/mooapp-ipc.h
mooutils/mooappinput-common.c
mooutils/mooappinput-priv.h
mooutils/mooappinput.h
mooutils/mooatom.h
mooutils/moobigpaned.c
mooutils/moobigpaned.h
mooutils/mooclosure.c
mooutils/mooclosure.h
mooutils/moocombo.c
mooutils/moocombo.h
mooutils/moocompat.h
mooutils/moodialogs.c
mooutils/mooeditops.c
mooutils/mooeditops.h
mooutils/mooencodings-data.h
mooutils/mooencodings.c
mooutils/mooencodings.h
mooutils/mooentry.cpp
mooutils/mooentry.h
mooutils/moofiledialog.c
mooutils/moofileicon.c
mooutils/moofileicon.h
mooutils/moofilewatch.c
mooutils/moofilewatch.h
mooutils/moofilewriter.cpp
mooutils/moofilewriter.h
mooutils/moofilewriter-private.h
mooutils/moofiltermgr.c
mooutils/moofiltermgr.h
mooutils/moofontsel.c
mooutils/moofontsel.h
mooutils/mooglade.c
mooutils/mooglade.h
mooutils/moohelp.c
mooutils/moohelp.h
mooutils/moohistorycombo.c
mooutils/moohistorycombo.h
mooutils/moohistorylist.c
mooutils/moohistorylist.h
mooutils/mooi18n.cpp
mooutils/mooi18n.h
mooutils/moolist.h
mooutils/moomarkup.c
mooutils/moomarkup.h
mooutils/moomenu.c
mooutils/moomenu.h
mooutils/moomenuaction.c
mooutils/moomenuaction.h
mooutils/moomenumgr.c
mooutils/moomenumgr.h
mooutils/moomenutoolbutton.c
mooutils/moomenutoolbutton.h
mooutils/moo-mime.c
mooutils/moo-mime.h
mooutils/moonotebook.c
mooutils/moonotebook.h
mooutils/mooonce.h
mooutils/moopane.c
mooutils/moopane.h
mooutils/moopaned.c
mooutils/moopaned.h
mooutils/mooprefs.c
mooutils/mooprefs.h
mooutils/mooprefsdialog.c
mooutils/mooprefsdialog.h
mooutils/mooprefspage.c
mooutils/mooprefspage.h
mooutils/moospawn.c
mooutils/moospawn.h
mooutils/moostock.c
mooutils/moostock.h
mooutils/mootype-macros.h
mooutils/moouixml.c
mooutils/mooundo.c
mooutils/mooundo.h
mooutils/mooutils.h
mooutils/mooutils-debug.h
mooutils/mooutils-enums.c
mooutils/mooutils-enums.h
mooutils/mooutils-file.c
mooutils/mooutils-file.h
mooutils/mooutils-fs.cpp
mooutils/mooutils-fs.h
mooutils/mooutils-gobject-private.h
mooutils/mooutils-gobject.cpp
mooutils/mooutils-gobject.h
mooutils/mooutils-macros.h
mooutils/mooutils-mem.h
mooutils/mooutils-messages.h
mooutils/mooutils-misc.cpp
mooutils/mooutils-misc.h
mooutils/mooutils-script.c
mooutils/mooutils-script.h
mooutils/mooutils-tests.h
mooutils/mooutils-treeview.c
mooutils/mooutils-treeview.h
mooutils/moowindow.c
mooutils/stock-file-24.h
mooutils/stock-file-selector-24.h
mooutils/stock-terminal-24.h
)
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/genmarshals_c.cmake
@ -171,7 +171,7 @@ LIST(APPEND built_mooutils_sources marshals.c)
# endif
SET(mooutils_win32_sources
mooutils/mooutils-win32.c
mooutils/mooutils-win32.cpp
mooutils/mooutils-dialog-win32.cpp
mooutils/moofiledialog-win32.h
mooutils/moofiledialog-win32.cpp
@ -188,7 +188,7 @@ if(MOO_BUILD_FROM_MSVC)
endif()
SET(mooutils_unittest_sources
mooutils/moo-test-utils.c
mooutils/moo-test-utils.cpp
mooutils/moo-test-utils.h
mooutils/moo-test-macros.h
)

View File

@ -4,10 +4,17 @@
// #include "mooutils/mooutils-misc.h"
// #include "mooutils/mooutils-fs.h"
#ifdef __cplusplus
extern "C" {
#endif
#define fnmatch _moo_win32_fnmatch
int _moo_win32_fnmatch (const char *pattern,
const char *string,
int flags);
#ifdef __cplusplus
}
#endif
#endif /* MOO_FNMATCH_H */

View File

@ -4,8 +4,16 @@
/* for struct timeval */
#include <winsock.h>
#ifdef __cplusplus
extern "C" {
#endif
#define gettimeofday _moo_win32_gettimeofday
int _moo_win32_gettimeofday (struct timeval *tp,
void *tzp);
#ifdef __cplusplus
}
#endif
#endif /* MOO_SYS_TIME_H */