~ubuntu-branches/ubuntu/vivid/mygui/vivid

« back to all changes in this revision

Viewing changes to UnitTests/UnitTest_MultiList/UnitTest_List.h

  • Committer: Package Import Robot
  • Author(s): Scott Howard, Bret Curtis, Scott Howard
  • Date: 2014-09-18 17:57:48 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140918175748-dd8va78mvpw1jbes
Tags: 3.2.1-1
[ Bret Curtis ]
* Updated license for majority of files from LGPL to Expat (MIT)

[ Scott Howard ]
* New upstream release
* Updated patch to add build option for system GLEW libraries
* All patches accepted upstream except shared_libraries.patch
* Bumped SONAME due to dropped symbols, updated *.symbols and package
  names
* Updated license of debian/* to Expat with permission of all authors
* Don't install Doxygen autogenerated md5 and map files (thanks
  lintian)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*!
2
 
        @file
3
 
        @author         Albert Semenov
4
 
        @date           10/2008
5
 
*/
6
 
#ifndef __UNITTEST_LIST_H__
7
 
#define __UNITTEST_LIST_H__
8
 
 
9
 
#include "MyGUI.h"
10
 
#include "Mirror_List.h"
11
 
 
12
 
namespace unittest
13
 
{
14
 
        class UnitTest_List
15
 
        {
16
 
        private:
17
 
                MyGUI::ListBox* original_list;
18
 
                unittest::Mirror_List* mirror_list;
19
 
                size_t count_items;
20
 
 
21
 
        public:
22
 
                UnitTest_List()
23
 
                {
24
 
                        original_list = MyGUI::Gui::getInstance().createWidget<MyGUI::ListBox>("ListBox", MyGUI::IntCoord(100, 100, 100, 100), MyGUI::Align::Default, "Main");
25
 
                        mirror_list = new unittest::Mirror_List();
26
 
                        count_items = 0;
27
 
                }
28
 
 
29
 
                ~UnitTest_List()
30
 
                {
31
 
                        MyGUI::WidgetManager::getInstance().destroyWidget(original_list);
32
 
                        delete mirror_list;
33
 
                }
34
 
 
35
 
                void checkList()
36
 
                {
37
 
                        assert(count_items == original_list->getItemCount());
38
 
                        assert(original_list->getItemCount() == mirror_list->getItemCount());
39
 
 
40
 
                        for (size_t pos = 0; pos < count_items; ++pos)
41
 
                        {
42
 
                                assert(original_list->getItemNameAt(pos) == mirror_list->getItemNameAt(pos));
43
 
                                assert(*original_list->getItemDataAt<size_t>(pos) == *mirror_list->getItemDataAt<size_t>(pos));
44
 
                        }
45
 
 
46
 
                        original_list->_checkAlign();
47
 
                }
48
 
 
49
 
                void Begin()
50
 
                {
51
 
                        size_t count = original_list->getItemCount();
52
 
                        if (count == 0) return;
53
 
                        size_t index = ((size_t)rand() % count);
54
 
                        original_list->beginToItemAt(index);
55
 
 
56
 
                        checkList();
57
 
                }
58
 
 
59
 
                void Begin(size_t _count)
60
 
                {
61
 
                        while (_count > 0)
62
 
                        {
63
 
                                Begin();
64
 
                                --_count;
65
 
                        }
66
 
                }
67
 
 
68
 
                void AddItem()
69
 
                {
70
 
                        size_t item = (size_t)rand();
71
 
                        mirror_list->addItem(MyGUI::utility::toString(item), item);
72
 
                        original_list->addItem(MyGUI::utility::toString(item), item);
73
 
                        count_items ++;
74
 
 
75
 
                        checkList();
76
 
                }
77
 
 
78
 
                void AddItem(size_t _count)
79
 
                {
80
 
                        while (_count > 0)
81
 
                        {
82
 
                                AddItem();
83
 
                                --_count;
84
 
                        }
85
 
                }
86
 
 
87
 
                void InsertItem()
88
 
                {
89
 
                        size_t index = count_items == 0 ? 0 : ((size_t)rand() % count_items);
90
 
                        size_t item = (size_t)rand();
91
 
 
92
 
                        mirror_list->insertItemAt(index, MyGUI::utility::toString(item), item);
93
 
                        original_list->insertItemAt(index, MyGUI::utility::toString(item), item);
94
 
 
95
 
                        count_items ++;
96
 
 
97
 
                        checkList();
98
 
                }
99
 
 
100
 
                void InsertItem(size_t _count)
101
 
                {
102
 
                        while (_count > 0)
103
 
                        {
104
 
                                InsertItem();
105
 
                                --_count;
106
 
                        }
107
 
                }
108
 
 
109
 
                void RemoveItem()
110
 
                {
111
 
                        if (count_items == 0) return;
112
 
 
113
 
                        size_t index = count_items == 0 ? 0 : ((size_t)rand() % count_items);
114
 
 
115
 
                        mirror_list->removeItemAt(index);
116
 
                        original_list->removeItemAt(index);
117
 
 
118
 
                        count_items --;
119
 
 
120
 
                        checkList();
121
 
                }
122
 
 
123
 
                void RemoveItem(size_t _count)
124
 
                {
125
 
                        while (_count > 0)
126
 
                        {
127
 
                                RemoveItem();
128
 
                                --_count;
129
 
                        }
130
 
                }
131
 
 
132
 
                void RemoveAllItems()
133
 
                {
134
 
                        mirror_list->removeAllItems();
135
 
                        original_list->removeAllItems();
136
 
 
137
 
                        count_items = 0;
138
 
                        checkList();
139
 
                }
140
 
 
141
 
                void nextFrame()
142
 
                {
143
 
                        if (count_items > 100) RemoveAllItems();
144
 
 
145
 
                        size_t index = (size_t)rand() % 4;
146
 
                        size_t count = (size_t)rand() % 3;
147
 
 
148
 
                        if (index == 0) InsertItem(count);
149
 
                        else if (index == 1) AddItem(count);
150
 
                        else if (index == 2) RemoveItem(count);
151
 
                        else if (index == 3) Begin(count);
152
 
                }
153
 
 
154
 
        };
155
 
 
156
 
}
157
 
 
158
 
#endif // __UNITTEST_LIST_H__
 
1
/*!
 
2
        @file
 
3
        @author         Albert Semenov
 
4
        @date           10/2008
 
5
*/
 
6
#ifndef __UNITTEST_LIST_H__
 
7
#define __UNITTEST_LIST_H__
 
8
 
 
9
#include "MyGUI.h"
 
10
#include "Mirror_List.h"
 
11
 
 
12
namespace unittest
 
13
{
 
14
        class UnitTest_List
 
15
        {
 
16
        private:
 
17
                MyGUI::ListBox* original_list;
 
18
                unittest::Mirror_List* mirror_list;
 
19
                size_t count_items;
 
20
 
 
21
        public:
 
22
                UnitTest_List()
 
23
                {
 
24
                        original_list = MyGUI::Gui::getInstance().createWidget<MyGUI::ListBox>("ListBox", MyGUI::IntCoord(100, 100, 100, 100), MyGUI::Align::Default, "Main");
 
25
                        mirror_list = new unittest::Mirror_List();
 
26
                        count_items = 0;
 
27
                }
 
28
 
 
29
                ~UnitTest_List()
 
30
                {
 
31
                        MyGUI::WidgetManager::getInstance().destroyWidget(original_list);
 
32
                        delete mirror_list;
 
33
                }
 
34
 
 
35
                void checkList()
 
36
                {
 
37
                        assert(count_items == original_list->getItemCount());
 
38
                        assert(original_list->getItemCount() == mirror_list->getItemCount());
 
39
 
 
40
                        for (size_t pos = 0; pos < count_items; ++pos)
 
41
                        {
 
42
                                assert(original_list->getItemNameAt(pos) == mirror_list->getItemNameAt(pos));
 
43
                                assert(*original_list->getItemDataAt<size_t>(pos) == *mirror_list->getItemDataAt<size_t>(pos));
 
44
                        }
 
45
 
 
46
                        original_list->_checkAlign();
 
47
                }
 
48
 
 
49
                void Begin()
 
50
                {
 
51
                        size_t count = original_list->getItemCount();
 
52
                        if (count == 0) return;
 
53
                        size_t index = ((size_t)rand() % count);
 
54
                        original_list->beginToItemAt(index);
 
55
 
 
56
                        checkList();
 
57
                }
 
58
 
 
59
                void Begin(size_t _count)
 
60
                {
 
61
                        while (_count > 0)
 
62
                        {
 
63
                                Begin();
 
64
                                --_count;
 
65
                        }
 
66
                }
 
67
 
 
68
                void AddItem()
 
69
                {
 
70
                        size_t item = (size_t)rand();
 
71
                        mirror_list->addItem(MyGUI::utility::toString(item), item);
 
72
                        original_list->addItem(MyGUI::utility::toString(item), item);
 
73
                        count_items ++;
 
74
 
 
75
                        checkList();
 
76
                }
 
77
 
 
78
                void AddItem(size_t _count)
 
79
                {
 
80
                        while (_count > 0)
 
81
                        {
 
82
                                AddItem();
 
83
                                --_count;
 
84
                        }
 
85
                }
 
86
 
 
87
                void InsertItem()
 
88
                {
 
89
                        size_t index = count_items == 0 ? 0 : ((size_t)rand() % count_items);
 
90
                        size_t item = (size_t)rand();
 
91
 
 
92
                        mirror_list->insertItemAt(index, MyGUI::utility::toString(item), item);
 
93
                        original_list->insertItemAt(index, MyGUI::utility::toString(item), item);
 
94
 
 
95
                        count_items ++;
 
96
 
 
97
                        checkList();
 
98
                }
 
99
 
 
100
                void InsertItem(size_t _count)
 
101
                {
 
102
                        while (_count > 0)
 
103
                        {
 
104
                                InsertItem();
 
105
                                --_count;
 
106
                        }
 
107
                }
 
108
 
 
109
                void RemoveItem()
 
110
                {
 
111
                        if (count_items == 0) return;
 
112
 
 
113
                        size_t index = count_items == 0 ? 0 : ((size_t)rand() % count_items);
 
114
 
 
115
                        mirror_list->removeItemAt(index);
 
116
                        original_list->removeItemAt(index);
 
117
 
 
118
                        count_items --;
 
119
 
 
120
                        checkList();
 
121
                }
 
122
 
 
123
                void RemoveItem(size_t _count)
 
124
                {
 
125
                        while (_count > 0)
 
126
                        {
 
127
                                RemoveItem();
 
128
                                --_count;
 
129
                        }
 
130
                }
 
131
 
 
132
                void RemoveAllItems()
 
133
                {
 
134
                        mirror_list->removeAllItems();
 
135
                        original_list->removeAllItems();
 
136
 
 
137
                        count_items = 0;
 
138
                        checkList();
 
139
                }
 
140
 
 
141
                void nextFrame()
 
142
                {
 
143
                        if (count_items > 100) RemoveAllItems();
 
144
 
 
145
                        size_t index = (size_t)rand() % 4;
 
146
                        size_t count = (size_t)rand() % 3;
 
147
 
 
148
                        if (index == 0) InsertItem(count);
 
149
                        else if (index == 1) AddItem(count);
 
150
                        else if (index == 2) RemoveItem(count);
 
151
                        else if (index == 3) Begin(count);
 
152
                }
 
153
 
 
154
        };
 
155
 
 
156
}
 
157
 
 
158
#endif // __UNITTEST_LIST_H__