Added qmafw-gst-subtitles-renderer-0.0.55 for Meego Harmattan 1.2
[mafwsubrenderer] / qmafw-gst-subtitles-renderer / unittests / ut_Others / ut_Others.cpp
1 /* 
2  * This file is part of QMAFW 
3  *
4  * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights
5  * reserved.
6  *
7  * Contact: Visa Smolander <visa.smolander@nokia.com>
8  *
9  * This software, including documentation, is protected by copyright controlled
10  * by Nokia Corporation. All rights are reserved. Copying, including
11  * reproducing, storing, adapting or translating, any or all of this material
12  * requires the prior written consent of Nokia Corporation. This material also
13  * contains confidential information which may not be disclosed to others
14  * without the prior written consent of Nokia.
15  *
16  */
17  
18 #include <QTimer>
19
20 #include <string.h>
21 #include <glib.h>
22 #include <gst/gst.h>
23
24 #include "ut_Others.h"
25 #include "mafw-gst-renderer-utils.h"
26 #include "mafw-gst-renderer-worker.h"
27
28 #define UNUSED(x) (void)(x)
29
30 /* START OF STUB DEFINITIONS */
31 gboolean g_utf8_validate(const gchar *str,
32                          gssize max_len,
33                          const gchar **end)
34 {
35
36     UNUSED(max_len);
37     UNUSED(end);
38
39     if (g_str_equal("valid", str))
40     {
41         return TRUE;
42     }
43     else
44     {
45         return FALSE;
46     }
47
48 }
49
50 gchar* g_locale_to_utf8(const gchar *opsysstring,
51                         gssize len,
52                         gsize *bytes_read,
53                         gsize *bytes_written,
54                         GError **error)
55 {
56
57     UNUSED(len);
58     UNUSED(bytes_read);
59     UNUSED(bytes_written);
60
61     if (g_str_equal("non-valid", opsysstring))
62     {
63         return g_strdup(opsysstring);
64     }
65     else
66     {
67         g_set_error(error,
68                     g_quark_from_string("test"),
69                     100,
70                     "%s", "SIMULATED ERROR");
71         return NULL;
72     }
73 }
74
75
76 /* END OF STUB DEFINITIONS */
77
78 void ut_Others::testUtils()
79 {
80     QVERIFY(uri_is_stream("file:///file.m3u") == FALSE);
81     QVERIFY(uri_is_stream("http:///joojoo.com") == TRUE);
82     QVERIFY(uri_is_stream(NULL) == FALSE);
83
84     gchar *dst = NULL;
85     QVERIFY(convert_utf8(NULL, NULL) == FALSE);
86     QVERIFY(convert_utf8("valid", NULL) == FALSE);
87     QVERIFY(convert_utf8(NULL, &dst) == FALSE);
88     QVERIFY(convert_utf8("valid", &dst) == TRUE);
89     g_free(dst);
90     QVERIFY(convert_utf8("non-valid", &dst) == TRUE);
91     QVERIFY(dst);
92     QVERIFY(g_str_equal(dst, "non-valid") == TRUE);
93     g_free(dst);
94     QVERIFY(convert_utf8("error", &dst) == FALSE);
95
96 }
97
98 void ut_Others::testGstErrorRemapping()
99 {
100
101     GQuark domain = g_quark_from_string("test_error_domain");
102
103     GError* error = g_error_new_literal(domain, 999, "error_message");
104     QVERIFY(remap_gst_error_code(error) == 999);
105
106     error->domain = GST_RESOURCE_ERROR;
107     error->code = GST_RESOURCE_ERROR_READ;
108     QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_STREAM_DISCONNECTED);
109     error->code = GST_RESOURCE_ERROR_NOT_FOUND;
110     QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_MEDIA_NOT_FOUND);
111     error->code = GST_RESOURCE_ERROR_OPEN_READ_WRITE;
112     QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_MEDIA_NOT_FOUND);
113     error->code = GST_RESOURCE_ERROR_NO_SPACE_LEFT;
114     QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_UNABLE_TO_PERFORM);
115     error->code = GST_RESOURCE_ERROR_WRITE;
116     QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_CORRUPTED_FILE);
117     error->code = GST_RESOURCE_ERROR_SEEK;
118     QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_CANNOT_SET_POSITION);
119     error->code = 999999;
120     QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_UNABLE_TO_PERFORM);
121
122     error->domain = GST_STREAM_ERROR;
123     error->code = GST_STREAM_ERROR_TYPE_NOT_FOUND;
124     QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_TYPE_NOT_AVAILABLE);
125     error->code = GST_STREAM_ERROR_FORMAT;
126     QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_UNSUPPORTED_TYPE);
127     error->code = GST_STREAM_ERROR_DECODE;
128     QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_CORRUPTED_FILE);
129     error->code = GST_STREAM_ERROR_CODEC_NOT_FOUND;
130     QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_CODEC_NOT_FOUND);
131     error->code = GST_STREAM_ERROR_DECRYPT;
132     QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_DRM_NOT_ALLOWED);
133     error->code = 999999;
134     QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_UNABLE_TO_PERFORM);
135
136     g_error_free(error);
137
138 }
139
140 void ut_Others::init()
141 {
142
143 }
144
145 void ut_Others::cleanup()
146 {
147
148 }
149
150 QTEST_APPLESS_MAIN(ut_Others)