From c79a605b8f487db2ab5e194b50f44345b649a15e Mon Sep 17 00:00:00 2001
From: Nikolai Kosjar <nikolai.kosjar@digia.com>
Date: Mon, 14 Oct 2013 14:05:34 +0200
Subject: [PATCH] CppEditor: Tests: Add basic tests for quick fix
 CompleteSwitchCaseStatement

Change-Id: Idd9773c9f5165ac8a378ee109bf270641a2b3749
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
---
 src/plugins/cppeditor/cppeditorplugin.h    |   4 +
 src/plugins/cppeditor/cppquickfix_test.cpp | 112 +++++++++++++++++++++
 2 files changed, 116 insertions(+)

diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h
index c1eb519de1e..d4c5474c64b 100644
--- a/src/plugins/cppeditor/cppeditorplugin.h
+++ b/src/plugins/cppeditor/cppeditorplugin.h
@@ -153,6 +153,10 @@ private slots:
     void test_doxygen_comments_cpp_styleA_indented_continuation();
     void test_doxygen_comments_cpp_styleA_corner_case();
 
+    void test_quickfix_CompleteSwitchCaseStatement_basic1();
+    void test_quickfix_CompleteSwitchCaseStatement_basic2();
+    void test_quickfix_CompleteSwitchCaseStatement_oneValueMissing();
+
     void test_quickfix_GenerateGetterSetter_basicGetterWithPrefix();
     void test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAndNamespace();
     void test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAndNamespaceToCpp();
diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp
index 31c4b6513f1..b1bc78d2920 100644
--- a/src/plugins/cppeditor/cppquickfix_test.cpp
+++ b/src/plugins/cppeditor/cppquickfix_test.cpp
@@ -349,6 +349,118 @@ private:
 
 } // anonymous namespace
 
+/// Checks: All enum values are added as case statements for a blank switch.
+void CppEditorPlugin::test_quickfix_CompleteSwitchCaseStatement_basic1()
+{
+    const QByteArray original =
+        "enum EnumType { V1, V2 };\n"
+        "\n"
+        "void f()\n"
+        "{\n"
+        "    EnumType t;\n"
+        "    @switch (t) {\n"
+        "    }\n"
+        "}\n";
+        ;
+    const QByteArray expected =
+        "enum EnumType { V1, V2 };\n"
+        "\n"
+        "void f()\n"
+        "{\n"
+        "    EnumType t;\n"
+        "    switch (t) {\n"
+        "    case V1:\n"
+        "        break;\n"
+        "    case V2:\n"
+        "        break;\n"
+        "    }\n"
+        "}\n"
+        "\n"
+        ;
+
+    CompleteSwitchCaseStatement factory;
+    TestCase data(original, expected);
+    data.run(&factory);
+}
+
+/// Checks: All enum values are added as case statements for a blank switch with a default case.
+void CppEditorPlugin::test_quickfix_CompleteSwitchCaseStatement_basic2()
+{
+    const QByteArray original =
+        "enum EnumType { V1, V2 };\n"
+        "\n"
+        "void f()\n"
+        "{\n"
+        "    EnumType t;\n"
+        "    @switch (t) {\n"
+        "    default:\n"
+        "        break;\n"
+        "    }\n"
+        "}\n";
+        ;
+    const QByteArray expected =
+        "enum EnumType { V1, V2 };\n"
+        "\n"
+        "void f()\n"
+        "{\n"
+        "    EnumType t;\n"
+        "    switch (t) {\n"
+        "    case V1:\n"
+        "        break;\n"
+        "    case V2:\n"
+        "        break;\n"
+        "    default:\n"
+        "        break;\n"
+        "    }\n"
+        "}\n"
+        "\n"
+        ;
+
+    CompleteSwitchCaseStatement factory;
+    TestCase data(original, expected);
+    data.run(&factory);
+}
+
+/// Checks: The missing enum value is added.
+void CppEditorPlugin::test_quickfix_CompleteSwitchCaseStatement_oneValueMissing()
+{
+    const QByteArray original =
+        "enum EnumType { V1, V2 };\n"
+        "\n"
+        "void f()\n"
+        "{\n"
+        "    EnumType t;\n"
+        "    @switch (t) {\n"
+        "    case V2:\n"
+        "        break;\n"
+        "    default:\n"
+        "        break;\n"
+        "    }\n"
+        "}\n";
+        ;
+    const QByteArray expected =
+        "enum EnumType { V1, V2 };\n"
+        "\n"
+        "void f()\n"
+        "{\n"
+        "    EnumType t;\n"
+        "    switch (t) {\n"
+        "    case V1:\n"
+        "        break;\n"
+        "    case V2:\n"
+        "        break;\n"
+        "    default:\n"
+        "        break;\n"
+        "    }\n"
+        "}\n"
+        "\n"
+        ;
+
+    CompleteSwitchCaseStatement factory;
+    TestCase data(original, expected);
+    data.run(&factory);
+}
+
 /// Checks:
 /// 1. If the name does not start with ("m_" or "_") and does not
 ///    end with "_", we are forced to prefix the getter with "get".
-- 
GitLab