Added qmafw-gst-subtitles-renderer-0.0.55 for Meego Harmattan 1.2
[mafwsubrenderer] / qmafw-gst-subtitles-renderer / unittests / ut_Others / ut_Others.cpp
diff --git a/qmafw-gst-subtitles-renderer/unittests/ut_Others/ut_Others.cpp b/qmafw-gst-subtitles-renderer/unittests/ut_Others/ut_Others.cpp
new file mode 100644 (file)
index 0000000..a820cc1
--- /dev/null
@@ -0,0 +1,150 @@
+/* 
+ * This file is part of QMAFW 
+ *
+ * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights
+ * reserved.
+ *
+ * Contact: Visa Smolander <visa.smolander@nokia.com>
+ *
+ * This software, including documentation, is protected by copyright controlled
+ * by Nokia Corporation. All rights are reserved. Copying, including
+ * reproducing, storing, adapting or translating, any or all of this material
+ * requires the prior written consent of Nokia Corporation. This material also
+ * contains confidential information which may not be disclosed to others
+ * without the prior written consent of Nokia.
+ *
+ */
+#include <QTimer>
+
+#include <string.h>
+#include <glib.h>
+#include <gst/gst.h>
+
+#include "ut_Others.h"
+#include "mafw-gst-renderer-utils.h"
+#include "mafw-gst-renderer-worker.h"
+
+#define UNUSED(x) (void)(x)
+
+/* START OF STUB DEFINITIONS */
+gboolean g_utf8_validate(const gchar *str,
+                         gssize max_len,
+                         const gchar **end)
+{
+
+    UNUSED(max_len);
+    UNUSED(end);
+
+    if (g_str_equal("valid", str))
+    {
+        return TRUE;
+    }
+    else
+    {
+        return FALSE;
+    }
+
+}
+
+gchar* g_locale_to_utf8(const gchar *opsysstring,
+                        gssize len,
+                        gsize *bytes_read,
+                        gsize *bytes_written,
+                        GError **error)
+{
+
+    UNUSED(len);
+    UNUSED(bytes_read);
+    UNUSED(bytes_written);
+
+    if (g_str_equal("non-valid", opsysstring))
+    {
+        return g_strdup(opsysstring);
+    }
+    else
+    {
+        g_set_error(error,
+                    g_quark_from_string("test"),
+                    100,
+                    "%s", "SIMULATED ERROR");
+        return NULL;
+    }
+}
+
+
+/* END OF STUB DEFINITIONS */
+
+void ut_Others::testUtils()
+{
+    QVERIFY(uri_is_stream("file:///file.m3u") == FALSE);
+    QVERIFY(uri_is_stream("http:///joojoo.com") == TRUE);
+    QVERIFY(uri_is_stream(NULL) == FALSE);
+
+    gchar *dst = NULL;
+    QVERIFY(convert_utf8(NULL, NULL) == FALSE);
+    QVERIFY(convert_utf8("valid", NULL) == FALSE);
+    QVERIFY(convert_utf8(NULL, &dst) == FALSE);
+    QVERIFY(convert_utf8("valid", &dst) == TRUE);
+    g_free(dst);
+    QVERIFY(convert_utf8("non-valid", &dst) == TRUE);
+    QVERIFY(dst);
+    QVERIFY(g_str_equal(dst, "non-valid") == TRUE);
+    g_free(dst);
+    QVERIFY(convert_utf8("error", &dst) == FALSE);
+
+}
+
+void ut_Others::testGstErrorRemapping()
+{
+
+    GQuark domain = g_quark_from_string("test_error_domain");
+
+    GError* error = g_error_new_literal(domain, 999, "error_message");
+    QVERIFY(remap_gst_error_code(error) == 999);
+
+    error->domain = GST_RESOURCE_ERROR;
+    error->code = GST_RESOURCE_ERROR_READ;
+    QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_STREAM_DISCONNECTED);
+    error->code = GST_RESOURCE_ERROR_NOT_FOUND;
+    QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_MEDIA_NOT_FOUND);
+    error->code = GST_RESOURCE_ERROR_OPEN_READ_WRITE;
+    QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_MEDIA_NOT_FOUND);
+    error->code = GST_RESOURCE_ERROR_NO_SPACE_LEFT;
+    QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_UNABLE_TO_PERFORM);
+    error->code = GST_RESOURCE_ERROR_WRITE;
+    QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_CORRUPTED_FILE);
+    error->code = GST_RESOURCE_ERROR_SEEK;
+    QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_CANNOT_SET_POSITION);
+    error->code = 999999;
+    QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_UNABLE_TO_PERFORM);
+
+    error->domain = GST_STREAM_ERROR;
+    error->code = GST_STREAM_ERROR_TYPE_NOT_FOUND;
+    QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_TYPE_NOT_AVAILABLE);
+    error->code = GST_STREAM_ERROR_FORMAT;
+    QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_UNSUPPORTED_TYPE);
+    error->code = GST_STREAM_ERROR_DECODE;
+    QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_CORRUPTED_FILE);
+    error->code = GST_STREAM_ERROR_CODEC_NOT_FOUND;
+    QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_CODEC_NOT_FOUND);
+    error->code = GST_STREAM_ERROR_DECRYPT;
+    QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_DRM_NOT_ALLOWED);
+    error->code = 999999;
+    QVERIFY(remap_gst_error_code(error) == WORKER_ERROR_UNABLE_TO_PERFORM);
+
+    g_error_free(error);
+
+}
+
+void ut_Others::init()
+{
+
+}
+
+void ut_Others::cleanup()
+{
+
+}
+
+QTEST_APPLESS_MAIN(ut_Others)