summaryrefslogtreecommitdiff
path: root/src/test/libical-glib/array.py
blob: 4d72ad0d34b83a55f43b648b949aa22ed7afadb2 (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
#!/usr/bin/env python3
# GI_TYPELIB_PATH=$PREFIX/lib/girepository-1.0/ ./array.py

###############################################################################
#
# SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org>
#
# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
#
###############################################################################

''' Test Python bindings for libical arrays '''

import gi
gi.require_version('ICalGLib', '3.0')
from gi.repository import ICalGLib  # nopep8 # pylint: disable=wrong-import-position

array = ICalGLib.Timezone.array_new()

# TEST APPEND
zone0 = ICalGLib.Timezone.get_builtin_timezone("Pacific/Midway")
zone1 = ICalGLib.Timezone.get_builtin_timezone("America/Vancouver")
zone2 = ICalGLib.Timezone.get_builtin_timezone("Atlantic/Bermuda")
zone3 = ICalGLib.Timezone.get_builtin_timezone("Africa/Casablanca")
zone4 = ICalGLib.Timezone.get_builtin_timezone("Asia/Irkutsk")

ICalGLib.Timezone.array_append_from_vtimezone(array, zone0.get_component())
ICalGLib.Timezone.array_append_from_vtimezone(array, zone1.get_component())
ICalGLib.Timezone.array_append_from_vtimezone(array, zone2.get_component())
ICalGLib.Timezone.array_append_from_vtimezone(array, zone3.get_component())
ICalGLib.Timezone.array_append_from_vtimezone(array, zone4.get_component())

assert array.size() == 5

z0 = ICalGLib.Timezone.array_element_at(array, 0)
assert z0.get_location() == zone0.get_location()
z1 = ICalGLib.Timezone.array_element_at(array, 1)
assert z1.get_location() == zone1.get_location()
z2 = ICalGLib.Timezone.array_element_at(array, 2)
assert z2.get_location() == zone2.get_location()
z3 = ICalGLib.Timezone.array_element_at(array, 3)
assert z3.get_location() == zone3.get_location()
z4 = ICalGLib.Timezone.array_element_at(array, 4)
assert z4.get_location() == zone4.get_location()

array2 = array.copy()

assert array2.size() == 5

z0 = ICalGLib.Timezone.array_element_at(array2, 0)
assert z0.get_location() == zone0.get_location()
z1 = ICalGLib.Timezone.array_element_at(array2, 1)
assert z1.get_location() == zone1.get_location()
z2 = ICalGLib.Timezone.array_element_at(array2, 2)
assert z2.get_location() == zone2.get_location()
z3 = ICalGLib.Timezone.array_element_at(array2, 3)
assert z3.get_location() == zone3.get_location()
z4 = ICalGLib.Timezone.array_element_at(array2, 4)
assert z4.get_location() == zone4.get_location()

array.remove_element_at(2)
assert array.size() == 4

z0 = ICalGLib.Timezone.array_element_at(array, 0)
assert z0.get_location() == zone0.get_location()
z1 = ICalGLib.Timezone.array_element_at(array, 1)
assert z1.get_location() == zone1.get_location()
z3 = ICalGLib.Timezone.array_element_at(array, 2)
assert z3.get_location() == zone3.get_location()
z4 = ICalGLib.Timezone.array_element_at(array, 3)
assert z4.get_location() == zone4.get_location()