~people-project/people-core/deep-refactoring

« back to all changes in this revision

Viewing changes to people-libs/people/base-test/test-contact.vala

  • Committer: Ali Sabil
  • Date: 2009-01-29 23:42:18 UTC
  • Revision ID: ali.sabil@gmail.com-20090129234218-avnl7d1dr6rsyp9d
- Ported people-libs/people/base-test to use libcore

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *
19
19
 */
20
20
 
21
 
using Gee;
22
21
 
23
22
using People;
24
 
using People.Utils;
 
23
using Core.Async;
 
24
using Core.Container;
25
25
 
26
26
 
27
27
namespace People.Backend.Test {
28
28
 
29
 
        public abstract class Contact : TestIt.Suite {
 
29
        public abstract class Contact : Core.Trial.Suite {
30
30
                protected string backend_name = "Null";
31
31
                protected string contact_id = null;
32
32
                protected Backend.ContactFlags contact_flags;
33
 
                protected Gee.Set<string> mandatory_fields;
34
 
                protected Gee.Set<string> defined_fields;
35
 
                protected Gee.Set<string> definable_fields;
 
33
                protected Set<string> mandatory_fields;
 
34
                protected Set<string> defined_fields;
 
35
                protected Set<string> definable_fields;
36
36
 
37
37
                protected People.Backend.Contact contact;
 
38
                private Set<string> fields_reference;
38
39
 
39
40
                protected override void initialize () {
40
41
                        name = "People::Backend::%s::Contact".printf (backend_name);
46
47
                        add_test_case ("set fields", test_set_fields);
47
48
                        add_test_case ("get fields", test_get_fields);
48
49
 
49
 
                        mandatory_fields = new Gee.HashSet<string> (str_hash, str_equal);
50
 
                        definable_fields = new Gee.HashSet<string> (str_hash, str_equal);
51
 
                        defined_fields = new Gee.HashSet<string> (str_hash, str_equal);
 
50
                        mandatory_fields = new Core.Container.HashSet<string> (str_hash, str_equal);
 
51
                        definable_fields = new Core.Container.HashSet<string> (str_hash, str_equal);
 
52
                        defined_fields = new Core.Container.HashSet<string> (str_hash, str_equal);
52
53
                }
53
54
 
54
55
                protected override void set_up () {
70
71
                }
71
72
 
72
73
                private void test_mandatory_fields () {
73
 
                        contact.get_mandatory_fields().add_callback(
74
 
                                        fields_callback, mandatory_fields);
 
74
                        fields_reference = mandatory_fields;
 
75
                        contact.get_mandatory_fields().add_callback(fields_callback);
75
76
                        async_wait ();
76
77
                }
77
78
 
78
79
                private void test_defined_fields () {
79
 
                        contact.get_defined_fields().add_callback(
80
 
                                        fields_callback, defined_fields);
 
80
                        fields_reference = defined_fields;
 
81
                        contact.get_defined_fields().add_callback(fields_callback);
81
82
                        async_wait ();
82
83
                }
83
84
 
84
85
                private void test_definable_fields () {
85
 
                        contact.get_definable_fields().add_callback(
86
 
                                        fields_callback, definable_fields);
 
86
                        fields_reference = definable_fields;
 
87
                        contact.get_definable_fields().add_callback(fields_callback);
87
88
                        async_wait ();
88
89
                }
89
90
 
92
93
                                return;
93
94
                        }
94
95
 
95
 
                        var fields = new Gee.HashMap<string, string>(str_hash, str_equal, str_equal);
96
 
                        fields.set ("identity.name.first", "hello");
97
 
                        fields.set ("identity.name.last", "world");
98
 
 
99
 
                        AsyncOperationCallback callback = (op, data) => {
100
 
                                Gee.Set<string> fields;
 
96
                        AsyncResultCallback callback = (op) => {
 
97
                                Core.Container.Set<string> fields;
101
98
                                try {
102
 
                                        fields = (Gee.Set<string>) op.get_result();
 
99
                                        fields = (Core.Container.Set<string>) op.get();
103
100
                                        assert_true (fields != null);
104
101
                                } catch (Error e) {
105
102
                                        async_failure (e.message);
110
107
                                assert_true(fields.contains("identity.name.last"));
111
108
                                async_break ();
112
109
                        };
 
110
 
 
111
                        var fields = new Core.Container.HashMap<string, string>(str_hash, str_equal, str_equal);
 
112
                        fields.set ("identity.name.first", "hello");
 
113
                        fields.set ("identity.name.last", "world");
 
114
 
113
115
                        contact.set_fields(fields).add_callback(callback);
114
116
                        async_wait ();
115
117
                }
116
118
 
117
119
                private void test_get_fields () {
118
 
                        AsyncOperationCallback callback = (op, data) => {
119
 
                                Gee.Map<string> fields;
 
120
                        AsyncResultCallback callback = (op) => {
 
121
                                Core.Container.Map<string> fields;
120
122
                                try {
121
 
                                        fields = (Gee.Map<string>) op.get_result();
 
123
                                        fields = (Core.Container.Map<string>) op.get();
122
124
                                        assert_true (fields != null);
123
125
                                } catch (Error e) {
124
126
                                        async_failure (e.message);
133
135
                        async_wait ();
134
136
                }
135
137
 
136
 
                private void fields_callback (AsyncOperation<Gee.Set<string>> op, void* data) {
137
 
                        Gee.Set<string> reference = (Gee.Set<string>) data;
138
 
                        Gee.Set<string> fields;
 
138
                private void fields_callback (AsyncResult<Core.Container.Set<string>> op) {
 
139
                        Core.Container.Set<string> fields;
139
140
                        try {
140
 
                                fields = (Gee.Set<string>) op.get_result();
 
141
                                fields = (Core.Container.Set<string>) op.get();
141
142
                                assert_true (fields != null);
142
143
                        } catch (Error e) {
143
144
                                async_failure (e.message);
144
145
                                return;
145
146
                        }
146
147
 
147
 
                        assert_true (fields.size == reference.size);
 
148
                        assert_true (fields.size == fields_reference.size);
148
149
 
149
 
                        foreach (string field in reference) {
 
150
                        foreach (string field in fields_reference) {
150
151
                                assert_true (fields.contains (field));
151
152
                        }
152
153
 
153
154
                        foreach (string field in fields) {
154
 
                                assert_true (reference.contains (field));
 
155
                                assert_true (fields_reference.contains (field));
155
156
                        }
156
157
                        async_break ();
157
158
                }