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

« back to all changes in this revision

Viewing changes to people-libs/people/base-test/test-contact-source.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:
20
20
 
21
21
 
22
22
using People;
23
 
using People.Utils;
 
23
using Core.Async;
24
24
 
25
25
 
26
26
namespace People.Backend.Test {
27
27
 
28
 
        public abstract class ContactSource : TestIt.Suite {
 
28
        public abstract class ContactSource : Core.Trial.Suite {
29
29
                protected string backend_name = "Null";
30
30
                protected Backend.ContactSourceFlags contact_source_flags;
31
31
                protected uint contacts_count = 0;
58
58
                        contact_source = null;
59
59
                }
60
60
 
61
 
                private void async_callback (AsyncOperation op, void* data) {
 
61
                private void async_callback (AsyncResult async_result) {
62
62
                        async_break ();
63
63
                }
64
64
 
68
68
 
69
69
                private void test_request_contact_valid () {
70
70
                        try {
71
 
                                var op = contact_source.request_contact (valid_contact_handle);
72
 
                                op.add_callback (async_callback);
 
71
                                var async_result = contact_source.request_contact (valid_contact_handle);
 
72
                                async_result.add_callback (async_callback);
73
73
                                async_wait ();
74
74
 
75
 
                                var contact = op.get_result();
 
75
                                var contact = async_result.get();
76
76
                                assert_true (contact != null);
77
77
                        } catch (Error e) {
78
78
                                failure ();
81
81
 
82
82
                private void test_request_contact_invalid () {
83
83
                        try {
84
 
                                var op = contact_source.request_contact (invalid_contact_handle);
85
 
                                op.add_callback (async_callback);
 
84
                                var async_result = contact_source.request_contact (invalid_contact_handle);
 
85
                                async_result.add_callback (async_callback);
86
86
                                async_wait ();
87
87
 
88
 
                                op.get_result();
 
88
                                async_result.get();
89
89
                                failure ();
90
90
                        } catch (Error e) {
91
91
                                success ();
95
95
                private void test_request_contact_null () {
96
96
                        if (Backend.ContactSourceFlags.CAN_CREATE_CONTACT in contact_source.flags) {
97
97
                                try {
98
 
                                        var op = contact_source.request_contact (null);
99
 
                                        op.add_callback (async_callback);
 
98
                                        var async_result = contact_source.request_contact (null);
 
99
                                        async_result.add_callback (async_callback);
100
100
                                        async_wait ();
101
101
 
102
 
                                        var contact = op.get_result();
 
102
                                        var contact = async_result.get();
103
103
                                        assert_true (contact != null);
104
104
                                } catch (Error e) {
105
105
                                        failure ();
106
106
                                }
107
107
                        } else {
108
108
                                try {
109
 
                                        var op = contact_source.request_contact (null);
110
 
                                        op.add_callback (async_callback);
 
109
                                        var async_result = contact_source.request_contact (null);
 
110
                                        async_result.add_callback (async_callback);
111
111
                                        async_wait ();
112
112
 
113
 
                                        op.get_result();
 
113
                                        async_result.get();
114
114
                                        failure ();
115
115
                                } catch (Error e) {
116
116
                                        success ();
124
124
 
125
125
                        Backend.Contact contact = null;
126
126
                        try {
127
 
                                var op = contact_source.request_contact (null);
128
 
                                op.add_callback (async_callback);
 
127
                                var async_result = contact_source.request_contact (null);
 
128
                                async_result.add_callback (async_callback);
129
129
                                async_wait ();
130
130
 
131
 
                                contact = op.get_result();
 
131
                                contact = async_result.get();
132
132
                        } catch (Error e) {
133
133
                                failure ();
134
134
                        }
135
135
 
136
 
                        var fields = new Gee.HashMap<string, string>(str_hash, str_equal, str_equal);
 
136
                        var fields = new Core.Container.HashMap<string, string>(str_hash, str_equal, str_equal);
137
137
                        fields.set ("identity.name.first", "hello");
138
138
                        fields.set ("identity.name.last", "world");
139
139
                        contact.set_fields (fields);
149
149
                private void check_contacts_count(uint count) {
150
150
                        contacts_target_count = count;
151
151
                        var search = ((Backend.DumpableContactSource)contact_source).dump ();
152
 
                        search.hit_found += (src, contact) => {
153
 
                                                contacts_current_count++;
154
 
                                        };
155
 
                        search.done += src => {
156
 
                                                assert_true (contacts_current_count == contacts_target_count);
157
 
                                                contacts_current_count = 0;
158
 
                                                async_break ();
159
 
                                        };
160
 
                        search.start();
161
 
                        async_wait ();
 
152
                        try {
 
153
                                var contacts = search.get ();
 
154
                                contacts.added += (contacts, contact) => {
 
155
                                        contacts_current_count++;
 
156
                                };
 
157
                                search.notify["complete"] += src => {
 
158
                                        assert_true (contacts_current_count == contacts_target_count);
 
159
                                        contacts_current_count = 0;
 
160
                                        async_break ();
 
161
                                };
 
162
                                async_wait ();
 
163
                        } catch {
 
164
                                failure ();
 
165
                        }
162
166
                }
163
167
 
164
168
        }