summaryrefslogtreecommitdiffstats
path: root/src/test-stubs.cpp
blob: 3cfd265b41a9ba7abd4d561213e93e1f8388a6a1 (plain)
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
/** @file
 * @brief Alternate stub implementations for some functions.
 * 
 * This file exists only for the benefit of the linker when building tests,
 * to avoid circular dependencies. If some test causes link errors because of a function
 * it doesn't need, feel free to add a stub here.
 */
/* Authors: Krzysztof Kosiński <twwenk.pl@gmail.com>
 * This file is in the public domain.
 */

#include "preferences.h"
#include <glib.h>
#include <glib/gstdio.h>
#include <cstring>
#include <cstdlib>

int sp_main_gui(int /*argc*/, char const **/*argv*/) { return 0; }
int sp_main_console(int /*argc*/, char const **/*argv*/) { return 0; }

// stubbed out preferences implementation using a simple map
namespace Inkscape {

std::map<Glib::ustring, Preferences::Entry> _prefs;

Preferences::Preferences() :
    _prefs_basename(""),
    _prefs_dir(""),
    _prefs_filename(""),
    _prefs_doc(NULL),
    _use_gui(true),
    _quiet(false),
    _loaded(false),
    _writable(false)
{
}

Preferences::~Preferences()
{
}

void Preferences::load(bool /*use_gui*/, bool /*quiet*/) {}
void Preferences::save() {}

// getter methods

Preferences::Entry const Preferences::getEntry(Glib::ustring const &pref_path)
{
    return _prefs[pref_path];
}
void Preferences::setBool(Glib::ustring const &pref_path, bool value)
{
    _prefs[pref_path] = _create_pref_value(pref_path, (void const*) (value ? "1" : "0"));
}
void Preferences::setInt(Glib::ustring const &pref_path, int value)
{
    gchar *intstr = (gchar*) g_malloc(32);
    g_snprintf(intstr, 32, "%d", value);
    _prefs[pref_path] = _create_pref_value(pref_path, (void const*) intstr);
}
void Preferences::setDouble(Glib::ustring const &pref_path, double value)
{
    gchar *buf = (gchar*) g_malloc(G_ASCII_DTOSTR_BUF_SIZE);
    g_ascii_dtostr(buf, G_ASCII_DTOSTR_BUF_SIZE, value);
    _prefs[pref_path] = _create_pref_value(pref_path, (void const*) buf);
}
void Preferences::setString(Glib::ustring const &pref_path, Glib::ustring const &value)
{
    _prefs[pref_path] = _create_pref_value(pref_path, (void const*) g_strdup(value.data()));
}

bool Preferences::_extractBool(Entry const &v)
{
    gchar const *s = static_cast<gchar const *>(v._value);
    if ( !s[0] || !strcmp(s, "0") || !strcmp(s, "false") ) return false;
    return true;
}
int Preferences::_extractInt(Entry const &v)
{
    gchar const *s = static_cast<gchar const *>(v._value);
    if ( !strcmp(s, "true") ) return true;
    if ( !strcmp(s, "false") ) return false;
    return atoi(s);
}
double Preferences::_extractDouble(Entry const &v)
{
    gchar const *s = static_cast<gchar const *>(v._value);
    return g_ascii_strtod(s, NULL);
}

Glib::ustring Preferences::_extractString(Entry const &v)
{
    return Glib::ustring(static_cast<gchar const *>(v._value));
}
Preferences::Entry const Preferences::_create_pref_value(Glib::ustring const &path, void const *ptr)
{
    return Entry(path, ptr);
}

Preferences *Preferences::_instance = NULL;


} // namespace Inkscape


/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :