Files
clang-uml/docs/test_cases/t20024.md
2023-08-05 19:34:03 +02:00

13 KiB

t20024 - Switch statement sequence diagram test case

Config

compilation_database_dir: ..
output_directory: puml
diagrams:
  t20024_sequence:
    type: sequence
    glob:
      - ../../tests/t20024/t20024.cc
    include:
      namespaces:
        - clanguml::t20024
    using_namespace:
      - clanguml::t20024
    start_from:
      - function: "clanguml::t20024::tmain()"

Source code

File t20024.cc

namespace clanguml {
namespace t20024 {

enum enum_a { zero = 0, one = 1, two = 2, three = 3 };

enum class colors { red, orange, green };

struct A {
    int select(enum_a v)
    {
        switch (v) {
        case zero:
            return a0();
        case one:
            return a1();
        case two:
            return a2();
        default:
            return a3();
        }
    }

    int a0() { return 0; }
    int a1() { return 1; }
    int a2() { return 2; }
    int a3() { return 3; }
};

struct B {
    void select(colors c)
    {
        switch (c) {
        case colors::red:
            red();
            break;
        case colors::orange:
            orange();
            break;
        case colors::green:
            green();
            break;
        default:
            grey();
        }
    }

    void red() { }
    void orange() { }
    void green() { }
    void grey() { }
};

int tmain()
{
    A a;
    B b;

    a.select(enum_a::two);

    b.select(colors::green);

    return 0;
}
}
}

Generated UML diagrams

t20024_sequence

Generated JSON models

{
  "diagram_type": "sequence",
  "metadata": {
    "clang_uml_version": "0.3.8-13-g2e1013c",
    "llvm_version": "Ubuntu clang version 15.0.7",
    "schema_version": 1
  },
  "name": "t20024_sequence",
  "participants": [
    {
      "id": "1919714441225983014",
      "name": "clanguml::t20024::tmain()",
      "source_location": {
        "column": 5,
        "file": "../../tests/t20024/t20024.cc",
        "line": 53,
        "translation_unit": "../../tests/t20024/t20024.cc"
      },
      "type": "function"
    },
    {
      "id": "40786919835708828",
      "name": "clanguml::t20024::A",
      "source_location": {
        "column": 8,
        "file": "../../tests/t20024/t20024.cc",
        "line": 8,
        "translation_unit": "../../tests/t20024/t20024.cc"
      },
      "type": "class"
    },
    {
      "id": "933287014626440872",
      "name": "clanguml::t20024::B",
      "source_location": {
        "column": 8,
        "file": "../../tests/t20024/t20024.cc",
        "line": 29,
        "translation_unit": "../../tests/t20024/t20024.cc"
      },
      "type": "class"
    }
  ],
  "sequences": [
    {
      "messages": [
        {
          "from": {
            "activity_id": "1919714441225983014",
            "activity_name": "clanguml::t20024::tmain()",
            "participant_id": "1919714441225983014",
            "participant_name": "clanguml::t20024::tmain()"
          },
          "name": "select(enum_a)",
          "return_type": "int",
          "scope": "normal",
          "source_location": {
            "column": 5,
            "file": "../../tests/t20024/t20024.cc",
            "line": 58,
            "translation_unit": "../../tests/t20024/t20024.cc"
          },
          "to": {
            "activity_id": "1200587047701031901",
            "activity_name": "clanguml::t20024::A::select(enum_a)",
            "participant_id": "40786919835708828"
          },
          "type": "message"
        },
        {
          "activity_id": "1200587047701031901",
          "branches": [
            {
              "messages": [
                {
                  "from": {
                    "activity_id": "1200587047701031901",
                    "activity_name": "clanguml::t20024::A::select(enum_a)",
                    "participant_id": "40786919835708828"
                  },
                  "name": "a0()",
                  "return_type": "int",
                  "scope": "normal",
                  "source_location": {
                    "column": 20,
                    "file": "../../tests/t20024/t20024.cc",
                    "line": 13,
                    "translation_unit": "../../tests/t20024/t20024.cc"
                  },
                  "to": {
                    "activity_id": "1859614580641799156",
                    "activity_name": "clanguml::t20024::A::a0()",
                    "participant_id": "40786919835708828"
                  },
                  "type": "message"
                }
              ],
              "name": "zero",
              "type": "case"
            },
            {
              "messages": [
                {
                  "from": {
                    "activity_id": "1200587047701031901",
                    "activity_name": "clanguml::t20024::A::select(enum_a)",
                    "participant_id": "40786919835708828"
                  },
                  "name": "a1()",
                  "return_type": "int",
                  "scope": "normal",
                  "source_location": {
                    "column": 20,
                    "file": "../../tests/t20024/t20024.cc",
                    "line": 15,
                    "translation_unit": "../../tests/t20024/t20024.cc"
                  },
                  "to": {
                    "activity_id": "501598940454911460",
                    "activity_name": "clanguml::t20024::A::a1()",
                    "participant_id": "40786919835708828"
                  },
                  "type": "message"
                }
              ],
              "name": "one",
              "type": "case"
            },
            {
              "messages": [
                {
                  "from": {
                    "activity_id": "1200587047701031901",
                    "activity_name": "clanguml::t20024::A::select(enum_a)",
                    "participant_id": "40786919835708828"
                  },
                  "name": "a2()",
                  "return_type": "int",
                  "scope": "normal",
                  "source_location": {
                    "column": 20,
                    "file": "../../tests/t20024/t20024.cc",
                    "line": 17,
                    "translation_unit": "../../tests/t20024/t20024.cc"
                  },
                  "to": {
                    "activity_id": "1698866541173753340",
                    "activity_name": "clanguml::t20024::A::a2()",
                    "participant_id": "40786919835708828"
                  },
                  "type": "message"
                }
              ],
              "name": "two",
              "type": "case"
            },
            {
              "messages": [
                {
                  "from": {
                    "activity_id": "1200587047701031901",
                    "activity_name": "clanguml::t20024::A::select(enum_a)",
                    "participant_id": "40786919835708828"
                  },
                  "name": "a3()",
                  "return_type": "int",
                  "scope": "normal",
                  "source_location": {
                    "column": 20,
                    "file": "../../tests/t20024/t20024.cc",
                    "line": 19,
                    "translation_unit": "../../tests/t20024/t20024.cc"
                  },
                  "to": {
                    "activity_id": "490376438551958259",
                    "activity_name": "clanguml::t20024::A::a3()",
                    "participant_id": "40786919835708828"
                  },
                  "type": "message"
                }
              ],
              "name": "default",
              "type": "case"
            }
          ],
          "name": "switch",
          "type": "alt"
        },
        {
          "from": {
            "activity_id": "1919714441225983014",
            "activity_name": "clanguml::t20024::tmain()",
            "participant_id": "1919714441225983014",
            "participant_name": "clanguml::t20024::tmain()"
          },
          "name": "select(colors)",
          "return_type": "void",
          "scope": "normal",
          "source_location": {
            "column": 5,
            "file": "../../tests/t20024/t20024.cc",
            "line": 60,
            "translation_unit": "../../tests/t20024/t20024.cc"
          },
          "to": {
            "activity_id": "286108218156977422",
            "activity_name": "clanguml::t20024::B::select(colors)",
            "participant_id": "933287014626440872"
          },
          "type": "message"
        },
        {
          "activity_id": "286108218156977422",
          "branches": [
            {
              "messages": [
                {
                  "from": {
                    "activity_id": "286108218156977422",
                    "activity_name": "clanguml::t20024::B::select(colors)",
                    "participant_id": "933287014626440872"
                  },
                  "name": "red()",
                  "return_type": "void",
                  "scope": "normal",
                  "source_location": {
                    "column": 13,
                    "file": "../../tests/t20024/t20024.cc",
                    "line": 34,
                    "translation_unit": "../../tests/t20024/t20024.cc"
                  },
                  "to": {
                    "activity_id": "112014563206084467",
                    "activity_name": "clanguml::t20024::B::red()",
                    "participant_id": "933287014626440872"
                  },
                  "type": "message"
                }
              ],
              "name": "enum colors::red",
              "type": "case"
            },
            {
              "messages": [
                {
                  "from": {
                    "activity_id": "286108218156977422",
                    "activity_name": "clanguml::t20024::B::select(colors)",
                    "participant_id": "933287014626440872"
                  },
                  "name": "orange()",
                  "return_type": "void",
                  "scope": "normal",
                  "source_location": {
                    "column": 13,
                    "file": "../../tests/t20024/t20024.cc",
                    "line": 37,
                    "translation_unit": "../../tests/t20024/t20024.cc"
                  },
                  "to": {
                    "activity_id": "2222823236498505185",
                    "activity_name": "clanguml::t20024::B::orange()",
                    "participant_id": "933287014626440872"
                  },
                  "type": "message"
                }
              ],
              "name": "enum colors::orange",
              "type": "case"
            },
            {
              "messages": [
                {
                  "from": {
                    "activity_id": "286108218156977422",
                    "activity_name": "clanguml::t20024::B::select(colors)",
                    "participant_id": "933287014626440872"
                  },
                  "name": "green()",
                  "return_type": "void",
                  "scope": "normal",
                  "source_location": {
                    "column": 13,
                    "file": "../../tests/t20024/t20024.cc",
                    "line": 40,
                    "translation_unit": "../../tests/t20024/t20024.cc"
                  },
                  "to": {
                    "activity_id": "519021723720658376",
                    "activity_name": "clanguml::t20024::B::green()",
                    "participant_id": "933287014626440872"
                  },
                  "type": "message"
                }
              ],
              "name": "enum colors::green",
              "type": "case"
            },
            {
              "messages": [
                {
                  "from": {
                    "activity_id": "286108218156977422",
                    "activity_name": "clanguml::t20024::B::select(colors)",
                    "participant_id": "933287014626440872"
                  },
                  "name": "grey()",
                  "return_type": "void",
                  "scope": "normal",
                  "source_location": {
                    "column": 13,
                    "file": "../../tests/t20024/t20024.cc",
                    "line": 43,
                    "translation_unit": "../../tests/t20024/t20024.cc"
                  },
                  "to": {
                    "activity_id": "1813557671878544737",
                    "activity_name": "clanguml::t20024::B::grey()",
                    "participant_id": "933287014626440872"
                  },
                  "type": "message"
                }
              ],
              "name": "default",
              "type": "case"
            }
          ],
          "name": "switch",
          "type": "alt"
        }
      ],
      "start_from": {
        "id": 1919714441225983014,
        "location": "clanguml::t20024::tmain()"
      }
    }
  ],
  "using_namespace": "clanguml::t20024"
}