Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
folks
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
85
Issues
85
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
GNOME
folks
Commits
11b13fc8
Commit
11b13fc8
authored
Oct 15, 2012
by
Jeremy Whiting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eds: Add create_address_book and remove_address_book to Edsf.PersonaStore.
eds: Add create-remove-stores unit test.
parent
e3b3c1ce
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
233 additions
and
0 deletions
+233
-0
backends/eds/lib/edsf-persona-store.vala
backends/eds/lib/edsf-persona-store.vala
+52
-0
tests/eds/Makefile.am
tests/eds/Makefile.am
+5
-0
tests/eds/create-remove-stores.vala
tests/eds/create-remove-stores.vala
+176
-0
No files found.
backends/eds/lib/edsf-persona-store.vala
View file @
11b13fc8
...
...
@@ -74,6 +74,58 @@ public class Edsf.PersonaStore : Folks.PersonaStore
*/
public
override
string
type_id
{
get
{
return
BACKEND_NAME
;
}
}
/**
* Create a new address book with the given ID.
*
* A new Address Book will be created with the given ID and the EDS
* SourceRegistry will notice the new Address Book source and will emit
* source_added with the new {@link E.Source} object which {@link Eds.Backend}
* will then create a new {@link Edsf.PersonaStore} from.
*
* @param id the name and id for the new address book
* @throws GLib.Error
*
* @since UNRELEASED
*/
public
static
async
void
create_address_book
(
string
id
)
throws
GLib
.
Error
{
debug
(
"Creating addressbook %s"
,
id
);
/* In order to create a new Address Book with the given id we follow
* the guidelines explained here:
* https://live.gnome.org/Evolution/ESourceMigrationGuide#How_do_I_create_a_new_calendar_or_address_book.3F
* for setting the backend name and parent UID to "local" and
* "local-stub" respectively.
*/
E
.
Source
new_source
=
new
E
.
Source
.
with_uid
(
id
,
null
);
new_source
.
set_parent
(
"local-stub"
);
new_source
.
set_display_name
(
id
);
E
.
SourceAddressBook
ab_extension
=
(
E
.
SourceAddressBook
)
new_source
.
get_extension
(
"Address Book"
);
ab_extension
.
set_backend_name
(
"local"
);
E
.
SourceRegistry
registry
=
yield
create_source_registry
();
yield
registry
.
commit_source
(
new_source
,
null
);
}
/**
* Remove a persona store's address book permamently.
*
* This is a utility function to remove an {@link Edsf.PersonaStore}'s address
* book from the disk permanently. This simply wraps the EDS API to do
* the same.
*
* @param store the PersonaStore to delete the address book for.
* @throws GLib.Error
*
* @since UNRELEASED
*/
public
static
async
void
remove_address_book
(
Edsf
.
PersonaStore
store
)
throws
GLib
.
Error
{
yield
store
.
source
.
remove
(
null
);
}
private
void
_address_book_notify_read_only_cb
(
Object
address_book
,
ParamSpec
pspec
)
{
...
...
tests/eds/Makefile.am
View file @
11b13fc8
...
...
@@ -77,6 +77,7 @@ noinst_PROGRAMS = \
set-roles
\
link-personas-diff-stores
\
enable-disable-stores
\
create-remove-stores
\
set-is-favourite
\
$(NULL)
...
...
@@ -221,6 +222,10 @@ enable_disable_stores_SOURCES = \
enable-disable-stores.vala
\
$(NULL)
create_remove_stores_SOURCES
=
\
create-remove-stores.vala
\
$(NULL)
set_is_favourite_SOURCES
=
\
set-is-favourite.vala
\
$(NULL)
...
...
tests/eds/create-remove-stores.vala
0 → 100644
View file @
11b13fc8
/*
* Copyright (C) 2012 Collabora Ltd.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Jeremy Whiting <jeremy.whiting@collabora.com>
*
*/
using
Folks
;
using
Gee
;
public
class
CreateRemoveStoresTests
:
Folks
.
TestCase
{
private
GLib
.
MainLoop
_main_loop
;
private
EdsTest
.
Backend
?
_eds_backend
;
private
IndividualAggregator
_aggregator
;
private
HashMap
<
string
,
bool
>
_store_removed
;
private
HashMap
<
string
,
bool
>
_store_added
;
private
BackendStore
?
_backend_store
;
public
CreateRemoveStoresTests
()
{
base
(
"CreateRemoveStoresTests"
);
this
.
add_test
(
"test creating and removing of PersonaStores"
,
this
.
test_creating_removing_stores
);
}
public
override
void
set_up
()
{
this
.
_eds_backend
=
new
EdsTest
.
Backend
();
this
.
_store_removed
=
new
HashMap
<
string
,
bool
>
();
this
.
_store_added
=
new
HashMap
<
string
,
bool
>
();
this
.
_backend_store
=
BackendStore
.
dup
();
this
.
_eds_backend
.
set_up
();
/* We configure eds as the primary store */
var
config_val
=
"eds:%s"
.
printf
(
this
.
_eds_backend
.
address_book_uid
);
Environment
.
set_variable
(
"FOLKS_PRIMARY_STORE"
,
config_val
,
true
);
Environment
.
set_variable
(
"FOLKS_BACKEND_EDS_USE_ADDRESS_BOOKS"
,
"test:other:test1:test2"
,
true
);
}
public
override
void
tear_down
()
{
this
.
_eds_backend
.
tear_down
();
Environment
.
unset_variable
(
"FOLKS_PRIMARY_STORE"
);
Environment
.
unset_variable
(
"FOLKS_BACKEND_EDS_USE_ADDRESS_BOOKS"
);
this
.
_eds_backend
=
null
;
}
public
void
test_creating_removing_stores
()
{
this
.
_main_loop
=
new
GLib
.
MainLoop
(
null
,
false
);
this
.
_test_creating_removing_stores_async
.
begin
();
var
timer_id
=
Timeout
.
add_seconds
(
20
,
()
=>
{
this
.
_main_loop
.
quit
();
assert_not_reached
();
});
this
.
_main_loop
.
run
();
assert
(
this
.
_store_removed
.
size
>
0
);
foreach
(
bool
removed
in
this
.
_store_removed
.
values
)
{
assert
(
removed
==
true
);
}
GLib
.
Source
.
remove
(
timer_id
);
this
.
_aggregator
=
null
;
this
.
_main_loop
=
null
;
}
private
async
void
_test_creating_removing_stores_async
()
{
yield
this
.
_backend_store
.
prepare
();
this
.
_aggregator
=
new
IndividualAggregator
();
try
{
yield
this
.
_backend_store
.
load_backends
();
var
backend
=
this
.
_backend_store
.
enabled_backends
.
get
(
"eds"
);
assert
(
backend
!=
null
);
yield
this
.
_aggregator
.
prepare
();
assert
(
this
.
_aggregator
.
is_prepared
);
backend
.
persona_store_removed
.
connect
(
this
.
_store_removed_cb
);
backend
.
persona_store_added
.
connect
(
this
.
_store_added_cb
);
var
pstore
=
"test1"
;
this
.
_store_removed
[
pstore
]
=
false
;
this
.
_store_added
[
pstore
]
=
false
;
debug
(
"Creating addressbook test1"
);
yield
Edsf
.
PersonaStore
.
create_address_book
(
pstore
);
pstore
=
"test2"
;
this
.
_store_removed
[
pstore
]
=
false
;
this
.
_store_added
[
pstore
]
=
false
;
debug
(
"Creating addressbook test2"
);
yield
Edsf
.
PersonaStore
.
create_address_book
(
pstore
);
}
catch
(
GLib
.
Error
e
)
{
GLib
.
warning
(
"Error when calling prepare: %s\n"
,
e
.
message
);
}
}
private
void
_store_removed_cb
(
PersonaStore
store
)
{
assert
(
store
!=
null
);
debug
(
"store removed %s"
,
store
.
id
);
this
.
_store_removed
[
store
.
id
]
=
true
;
int
removed_count
=
0
;
foreach
(
bool
removed
in
this
.
_store_removed
.
values
)
{
if
(
removed
)
{
++
removed_count
;
}
}
debug
(
"removed_count is %d, expected size is %d\n"
,
removed_count
,
this
.
_store_removed
.
size
);
if
(
removed_count
==
this
.
_store_removed
.
size
)
{
this
.
_main_loop
.
quit
();
}
}
private
void
_store_added_cb
(
PersonaStore
store
)
{
debug
(
"store added %s"
,
store
.
id
);
this
.
_store_added
[
store
.
id
]
=
true
;
var
backend
=
this
.
_backend_store
.
enabled_backends
.
get
(
"eds"
);
assert
(
backend
!=
null
);
debug
(
"removing store %s"
,
store
.
id
);
Edsf
.
PersonaStore
.
remove_address_book
.
begin
((
Edsf
.
PersonaStore
)
store
);
}
}
public
int
main
(
string
[]
args
)
{
Test
.
init
(
ref
args
);
TestSuite
root
=
TestSuite
.
get_root
();
root
.
add_suite
(
new
CreateRemoveStoresTests
().
get_suite
());
Test
.
run
();
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment