@startuml
'https://plantuml.com/sequence-diagram
title
 <b><font size="24">Gtest 整体运行过程顺序图</font></b>

end title

'actor boundary control collections database entity queue
'participant "SubClass of Test"  as Test  << (C,#add1b2) subclass >> order -2 #business
participant "SubClass of Test"  as Test  order -2 #business
participant "main()" as main
participant "internal::InitGoogleTestImpl()" as init_impl
participant "ParseGoogleTestFlagsOnlyImpl" as ParseGoogleTestFlagsOnlyImpl
participant "RUN_ALL_TESTS()" as  run_all_tests order 100


'autonumber start increment "<u>0|#.</u>"
autonumber 1 1 "<b>."

'activate participant #colouml_sequence_diagram.pumlr
activate Test
'participant -> participant ++|--|**|!! #color"
Test -> Test  : invoke MakeAndRegisterTestInfo(...)

/'
group 主标题 [副标题]
    bob -[#red]> alice : hello
    [-> alice : DoWork
    create actor|control|boundary|control|... participant
    bob -> participant : new
    / (h|r)note left|right|over|across of alice: this is note
    ref over bob,alice : init
    ... 5分钟后 ...
    bob <[#blue]- alice : ret
    |||
    ||40||
    alt#alt背景色 #整体背景色 主标题
        break|critical|loop|opt|par 主标题

        end
    else 标题

    else 标题2

    end
end
'/

group InitGoogleTest [ Init GTest ]
    ?-> main  ++ #gold : run main()
    main -> main ++ : invoke InitGoogleTest()
    main -> init_impl ++ : invoke InitGoogleTestImpl() in gtest.cc
    init_impl -> init_impl ++ : invoke GTestIsInitialized()
    alt GTestIsInitialized [yes]
        return ret void
        |||
    end
    |||
    init_impl -> init_impl ++ : 判断是否没有参数
    alt *argc<=0 [yes]
        return ret void
    end
    init_impl -> init_impl : g_argvs.clear()
    init_impl -> init_impl : g_argvs.push_back()

    init_impl -> init_impl ++ : invoke ParseGoogleTestFlagsOnly()
        init_impl -> ParseGoogleTestFlagsOnlyImpl ++ #gold : invoke ParseGoogleTestFlagsOnlyImpl()
            loop  int i=0;i<*argc;++i
                ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl ++ #yellow : 循环判断参数数量
                    ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl ++ : invoke ParseGoogleTestFlag(arg)
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : 获取全局google参数变量值，前缀::testing::FLAGS_gtest_
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : 调用ParseFlag(),获取参数变量的值
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : invoke ParseFlagValue()
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : 获取gtest的参数key，增加--gtest_keyName
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : 判断用户传入参数是否是标准的gtest的参数
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : 如果是bool类型且没有=value,则直接返回'\0'
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : 如果没有'='，则直接返回 nullptr
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : 如果有则直接返回=后的value_str
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : 如果value_str 为nullptr,则直接返回false
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : 分三种类型: bool,int,string来获取value和返回true
                    return ret 是否google参数结果

                    alt 如果是google参数
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : 打印帮助信息,remove_flag=true
                    else 如果是含有gtest参数的文件方式
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : 设置gtest全名变量的值(::testing::FLAGS_gtest_flagfile)
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : 从文件中加载gtests全局参数,removed=true
                    else 如果是帮助参数
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : g_help_flag=true
                    end

                    alt remove_flag=true [is_remove_flag]
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : 使用参数移动的方法来消除用户输入的gtest参数
                        ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl  : 参数减1，(*argc)--
                    end
                return ret void
                |||
            end

            alt g_help_flag [yes]
                ParseGoogleTestFlagsOnlyImpl -> ParseGoogleTestFlagsOnlyImpl ++ : 屏幕打印帮助信息
                return ret void
                |||
            end
         return ret void
    return ret void

    init_impl -> init_impl ++ : GetUnitTestImpl()->PostFlagParsingInit()
    return ret void
    return ret void
    return ret void
    |||
end
|||


group invoke RUN_ALL_TESTS
    main -> main ++ :invoke RUN_ALL_TESTS()
    return ret int
   |||
end
|||

@enduml