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
|
/*
* SPDX-FileCopyrightText: 2017-2017 CSSlayer <wengxt@gmail.com>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
*/
#include "fcitx-utils/element.h"
#include "fcitx-utils/log.h"
namespace test {
class Element : public fcitx::Element {
public:
using fcitx::Element::addChild;
using fcitx::Element::addParent;
using fcitx::Element::childs;
using fcitx::Element::insertChild;
using fcitx::Element::insertParent;
using fcitx::Element::parents;
using fcitx::Element::removeChild;
using fcitx::Element::removeParent;
};
} // namespace test
int main() {
using test::Element;
{
Element e, e2;
e.addParent(&e2);
FCITX_ASSERT(e.parents().size() == 1);
FCITX_ASSERT(e.childs().empty());
FCITX_ASSERT(e2.parents().empty());
FCITX_ASSERT(e2.childs().size() == 1);
}
{
Element e, e2;
e.addParent(&e2);
e2.addParent(&e);
FCITX_ASSERT(e.parents().size() == 1);
FCITX_ASSERT(e.childs().size() == 1);
FCITX_ASSERT(e2.parents().size() == 1);
FCITX_ASSERT(e2.childs().size() == 1);
}
{
Element e, *e2 = new Element;
e.addParent(e2);
FCITX_ASSERT(e.parents().size() == 1);
FCITX_ASSERT(e.childs().empty());
FCITX_ASSERT(e2->parents().empty());
FCITX_ASSERT(e2->childs().size() == 1);
delete e2;
FCITX_ASSERT(e.parents().empty());
FCITX_ASSERT(e.childs().empty());
}
{
Element e, e2, e3;
e.addChild(&e2);
FCITX_ASSERT(e.childs().front() == &e2);
e.addChild(&e3);
FCITX_ASSERT(e.childs().front() == &e2);
FCITX_ASSERT(e.childs().back() == &e3);
e.insertChild(&e2, &e3);
// e3 is in, this is no op.
FCITX_ASSERT(e.childs().front() == &e2);
FCITX_ASSERT(e.childs().back() == &e3);
FCITX_ASSERT(e.childs().size() == 2);
e.removeChild(&e3);
e.insertChild(&e2, &e3);
FCITX_ASSERT(e.childs().front() == &e3);
FCITX_ASSERT(e.childs().back() == &e2);
FCITX_ASSERT(e.childs().size() == 2);
}
return 0;
}
|