summaryrefslogtreecommitdiff
path: root/indra/llcommon/tests/lazyeventapi_test.cpp
blob: 6639c5e54078c2643b004f76ffd48cd160bfc6c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
 * @file   lazyeventapi_test.cpp
 * @author Nat Goodspeed
 * @date   2022-06-18
 * @brief  Test for lazyeventapi.
 * 
 * $LicenseInfo:firstyear=2022&license=viewerlgpl$
 * Copyright (c) 2022, Linden Research, Inc.
 * $/LicenseInfo$
 */

// Precompiled header
#include "linden_common.h"
// associated header
#include "lazyeventapi.h"
// STL headers
// std headers
// external library headers
// other Linden headers
#include "../test/lltut.h"
#include "llevents.h"

// LLEventAPI listener subclass
class MyListener: public LLEventAPI
{
public:
    MyListener(const LL::LazyEventAPIParams& params):
        LLEventAPI(params)
    {}

    void get(const LLSD& event)
    {
        std::cout << "MyListener::get() got " << event << std::endl;
    }
};

// LazyEventAPI registrar subclass
class MyRegistrar: public LL::LazyEventAPI<MyListener>
{
    using super = LL::LazyEventAPI<MyListener>;
    using super::listener;
public:
    MyRegistrar():
        super("Test", "This is a test LLEventAPI")
    {
        add("get", "This is a get operation", &listener::get);            
    }
};
// Normally we'd declare a static instance of MyRegistrar -- but because we
// may want to test with and without, defer declaration to individual test
// methods.

/*****************************************************************************
*   TUT
*****************************************************************************/
namespace tut
{
    struct lazyeventapi_data
    {
        ~lazyeventapi_data()
        {
            // after every test, reset LLEventPumps
            LLEventPumps::deleteSingleton();
        }
    };
    typedef test_group<lazyeventapi_data> lazyeventapi_group;
    typedef lazyeventapi_group::object object;
    lazyeventapi_group lazyeventapigrp("lazyeventapi");

    template<> template<>
    void object::test<1>()
    {
        set_test_name("LazyEventAPI");
        // this is where the magic (should) happen
        // 'register' still a keyword until C++17
        MyRegistrar regster;
        LLEventPumps::instance().obtain("Test").post("hey");
    }

    template<> template<>
    void object::test<2>()
    {
        set_test_name("No LazyEventAPI");
        // Because the MyRegistrar declaration in test<1>() is local, because
        // it has been destroyed, we fully expect NOT to reach a MyListener
        // instance with this post.
        LLEventPumps::instance().obtain("Test").post("moot");
    }
} // namespace tut