Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
172d685b
Commit
172d685b
authored
2 years ago
by
Aline Gondim Santos
Browse files
Options
Downloads
Patches
Plain Diff
account details: add test to check deviceId presence
Change-Id: I971bd0821b358085c6d664b22818e54a24db5d2a
parent
7aaad7bb
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/unitTest/account_factory/testAccount_factory.cpp
+86
-36
86 additions, 36 deletions
test/unitTest/account_factory/testAccount_factory.cpp
with
86 additions
and
36 deletions
test/unitTest/account_factory/testAccount_factory.cpp
+
86
−
36
View file @
172d685b
...
...
@@ -21,17 +21,33 @@
#include
<cppunit/TestFixture.h>
#include
<cppunit/extensions/HelperMacros.h>
#include
<condition_variable>
#include
"account_factory.h"
#include
"../../test_runner.h"
#include
"jami.h"
#include
"account_const.h"
#include
"manager.h"
#include
"account_const.h"
#include
"account_schema.h"
#include
"common.h"
#include
"jamidht/jamiaccount.h"
using
namespace
std
::
literals
::
chrono_literals
;
namespace
jami
{
namespace
test
{
class
Account_factoryTest
:
public
CppUnit
::
TestFixture
{
public:
static
std
::
string
name
()
{
return
"account_factory"
;
}
Account_factoryTest
()
{
// Init daemon
libjami
::
init
(
libjami
::
InitFlag
(
libjami
::
LIBJAMI_FLAG_DEBUG
|
libjami
::
LIBJAMI_FLAG_CONSOLE_LOG
));
if
(
not
Manager
::
instance
().
initialized
)
CPPUNIT_ASSERT
(
libjami
::
start
(
"dring-sample.yml"
));
}
~
Account_factoryTest
()
{
libjami
::
fini
();
}
static
std
::
string
name
()
{
return
"Account_factory"
;
}
void
setUp
();
void
tearDown
();
...
...
@@ -48,7 +64,12 @@ private:
const
std
::
string
SIP_ID
=
"SIP_ID"
;
const
std
::
string
RING_ID
=
"RING_ID"
;
std
::
unique_ptr
<
AccountFactory
>
accountFactory
;
bool
sipReady
,
ringReady
,
accountsRemoved
;
size_t
initialAccounts
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
std
::
mutex
mtx
;
std
::
unique_lock
<
std
::
mutex
>
lk
{
mtx
};
std
::
condition_variable
cv
;
};
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
(
Account_factoryTest
,
Account_factoryTest
::
name
());
...
...
@@ -56,81 +77,110 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Account_factoryTest, Account_factoryTest::
void
Account_factoryTest
::
setUp
()
{
// Init daemon
libjami
::
init
(
libjami
::
InitFlag
(
libjami
::
LIBJAMI_FLAG_DEBUG
|
libjami
::
LIBJAMI_FLAG_CONSOLE_LOG
));
CPPUNIT_ASSERT
(
libjami
::
start
(
"jami-sample.yml"
));
accountFactory
.
reset
(
new
AccountFactory
);
sipReady
=
false
;
ringReady
=
false
;
accountsRemoved
=
false
;
initialAccounts
=
Manager
::
instance
().
accountCount
();
confHandlers
.
insert
(
libjami
::
exportable_callback
<
libjami
::
ConfigurationSignal
::
VolatileDetailsChanged
>
(
[
&
](
const
std
::
string
&
accountID
,
const
std
::
map
<
std
::
string
,
std
::
string
>&
details
)
{
if
(
accountID
!=
RING_ID
&&
accountID
!=
SIP_ID
)
{
return
;
}
try
{
ringReady
|=
accountID
==
RING_ID
&&
details
.
at
(
jami
::
Conf
::
CONFIG_ACCOUNT_REGISTRATION_STATUS
)
==
"REGISTERED"
&&
details
.
at
(
libjami
::
Account
::
VolatileProperties
::
DEVICE_ANNOUNCED
)
==
"true"
;
sipReady
|=
accountID
==
SIP_ID
&&
details
.
at
(
jami
::
Conf
::
CONFIG_ACCOUNT_REGISTRATION_STATUS
)
==
"READY"
;
}
catch
(
const
std
::
out_of_range
&
)
{}
}));
confHandlers
.
insert
(
libjami
::
exportable_callback
<
libjami
::
ConfigurationSignal
::
AccountsChanged
>
([
&
]()
{
if
(
jami
::
Manager
::
instance
().
getAccountList
().
size
()
<=
initialAccounts
)
{
accountsRemoved
=
true
;
}
}));
libjami
::
registerSignalHandlers
(
confHandlers
);
}
void
Account_factoryTest
::
tearDown
()
{
// Stop daemon
libjami
::
fini
();
libjami
::
unregisterSignalHandlers
();
}
void
Account_factoryTest
::
testAddRemoveSIPAccount
()
{
// verify if there is no account at the beginning
CPPUNIT_ASSERT
(
accountFactory
->
empty
());
CPPUNIT_ASSERT
(
accountFactory
->
accountCount
()
==
0
);
AccountFactory
*
accountFactory
=
&
Manager
::
instance
().
accountFactory
;
accountFactory
->
createAccount
(
libjami
::
Account
::
ProtocolNames
::
SIP
,
SIP_ID
);
auto
accDetails
=
libjami
::
getAccountTemplate
(
"SIP"
);
auto
newAccount
=
Manager
::
instance
().
addAccount
(
accDetails
,
SIP_ID
);
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
sipReady
;
}));
CPPUNIT_ASSERT
(
accountFactory
->
hasAccount
(
SIP_ID
));
CPPUNIT_ASSERT
(
!
accountFactory
->
hasAccount
(
RING_ID
));
CPPUNIT_ASSERT
(
!
accountFactory
->
empty
());
CPPUNIT_ASSERT
(
accountFactory
->
accountCount
()
==
1
);
CPPUNIT_ASSERT
(
accountFactory
->
accountCount
()
==
1
+
initialAccounts
);
auto
details
=
Manager
::
instance
().
getVolatileAccountDetails
(
SIP_ID
);
CPPUNIT_ASSERT
(
details
.
find
(
libjami
::
Account
::
ConfProperties
::
DEVICE_ID
)
==
details
.
end
());
accountFactory
->
removeAccount
(
SIP_ID
);
Manager
::
instance
().
removeAccount
(
SIP_ID
,
true
);
CPPUNIT_ASSERT
(
accountFactory
->
empty
());
CPPUNIT_ASSERT
(
accountFactory
->
accountCount
()
==
0
);
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
accountsRemoved
;
}));
}
void
Account_factoryTest
::
testAddRemoveRINGAccount
()
{
// verify if there is no account at the beginning
CPPUNIT_ASSERT
(
accountFactory
->
empty
());
CPPUNIT_ASSERT
(
accountFactory
->
accountCount
()
==
0
);
AccountFactory
*
accountFactory
=
&
Manager
::
instance
().
accountFactory
;
accountFactory
->
createAccount
(
libjami
::
Account
::
ProtocolNames
::
RING
,
RING_ID
);
auto
accDetails
=
libjami
::
getAccountTemplate
(
"RING"
);
auto
newAccount
=
Manager
::
instance
().
addAccount
(
accDetails
,
RING_ID
);
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
ringReady
;
}));
CPPUNIT_ASSERT
(
accountFactory
->
hasAccount
(
RING_ID
));
CPPUNIT_ASSERT
(
!
accountFactory
->
hasAccount
(
SIP_ID
));
CPPUNIT_ASSERT
(
!
accountFactory
->
empty
());
CPPUNIT_ASSERT
(
accountFactory
->
accountCount
()
==
1
);
CPPUNIT_ASSERT
(
accountFactory
->
accountCount
()
==
1
+
initialAccounts
);
accountFactory
->
removeAccount
(
RING_ID
);
auto
details
=
Manager
::
instance
().
getVolatileAccountDetails
(
RING_ID
);
CPPUNIT_ASSERT
(
details
.
find
(
libjami
::
Account
::
ConfProperties
::
DEVICE_ID
)
!=
details
.
end
());
CPPUNIT_ASSERT
(
accountFactory
->
empty
()
);
CPPUNIT_ASSERT
(
accountFactory
->
accountCount
()
==
0
);
Manager
::
instance
().
removeAccount
(
RING_ID
,
true
);
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
accountsRemoved
;
})
);
}
void
Account_factoryTest
::
testClear
()
{
AccountFactory
accountFactory
;
// verify if there is no account at the beginning
CPPUNIT_ASSERT
(
accountFactory
->
empty
());
CPPUNIT_ASSERT
(
accountFactory
->
accountCount
()
==
0
);
CPPUNIT_ASSERT
(
accountFactory
.
empty
());
CPPUNIT_ASSERT
(
accountFactory
.
accountCount
()
==
0
);
const
int
nbrAccount
=
5
;
for
(
int
i
=
0
;
i
<
nbrAccount
;
++
i
)
{
accountFactory
->
createAccount
(
libjami
::
Account
::
ProtocolNames
::
RING
,
RING_ID
+
std
::
to_string
(
i
));
accountFactory
.
createAccount
(
libjami
::
Account
::
ProtocolNames
::
RING
,
RING_ID
+
std
::
to_string
(
i
));
}
CPPUNIT_ASSERT
(
accountFactory
->
accountCount
()
==
nbrAccount
);
CPPUNIT_ASSERT
(
!
accountFactory
->
empty
());
CPPUNIT_ASSERT
(
accountFactory
.
accountCount
()
==
nbrAccount
);
CPPUNIT_ASSERT
(
!
accountFactory
.
empty
());
accountFactory
->
clear
();
accountFactory
.
clear
();
CPPUNIT_ASSERT
(
accountFactory
->
empty
());
CPPUNIT_ASSERT
(
accountFactory
->
accountCount
()
==
0
);
CPPUNIT_ASSERT
(
accountFactory
.
empty
());
CPPUNIT_ASSERT
(
accountFactory
.
accountCount
()
==
0
);
}
}}
// namespace jami::test
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment