Skip to content
GitLab
Explore
Sign in
Register
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
144defdb
Commit
144defdb
authored
4 years ago
by
Sébastien Blin
Committed by
Adrien Béraud
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
tests: fix fileTransfer test
Change-Id: Ibb1afba82e884913d1e8268fdd584dedef8ae496
parent
b416ecf6
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/fileTransfer/fileTransfer.cpp
+95
-112
95 additions, 112 deletions
test/unitTest/fileTransfer/fileTransfer.cpp
with
95 additions
and
112 deletions
test/unitTest/fileTransfer/fileTransfer.cpp
+
95
−
112
View file @
144defdb
...
@@ -34,19 +34,20 @@
...
@@ -34,19 +34,20 @@
using
namespace
DRing
::
Account
;
using
namespace
DRing
::
Account
;
namespace
jami
{
namespace
test
{
namespace
jami
{
namespace
test
{
class
FileTransferTest
:
public
CppUnit
::
TestFixture
{
class
FileTransferTest
:
public
CppUnit
::
TestFixture
{
public:
public:
FileTransferTest
()
{
FileTransferTest
()
{
// Init daemon
// Init daemon
DRing
::
init
(
DRing
::
InitFlag
(
DRing
::
DRING_FLAG_DEBUG
|
DRing
::
DRING_FLAG_CONSOLE_LOG
));
DRing
::
init
(
DRing
::
InitFlag
(
DRing
::
DRING_FLAG_DEBUG
|
DRing
::
DRING_FLAG_CONSOLE_LOG
));
if
(
not
Manager
::
instance
().
initialized
)
if
(
not
Manager
::
instance
().
initialized
)
CPPUNIT_ASSERT
(
DRing
::
start
(
"dring-sample.yml"
));
CPPUNIT_ASSERT
(
DRing
::
start
(
"dring-sample.yml"
));
}
}
~
FileTransferTest
()
{
~
FileTransferTest
()
{
DRing
::
fini
();
}
DRing
::
fini
();
}
static
std
::
string
name
()
{
return
"Call"
;
}
static
std
::
string
name
()
{
return
"Call"
;
}
bool
compare
(
const
std
::
string
&
fileA
,
const
std
::
string
&
fileB
)
const
;
bool
compare
(
const
std
::
string
&
fileA
,
const
std
::
string
&
fileB
)
const
;
void
setUp
();
void
setUp
();
...
@@ -68,7 +69,8 @@ private:
...
@@ -68,7 +69,8 @@ private:
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
(
FileTransferTest
,
FileTransferTest
::
name
());
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
(
FileTransferTest
,
FileTransferTest
::
name
());
bool
bool
FileTransferTest
::
compare
(
const
std
::
string
&
fileA
,
const
std
::
string
&
fileB
)
const
{
FileTransferTest
::
compare
(
const
std
::
string
&
fileA
,
const
std
::
string
&
fileB
)
const
{
std
::
ifstream
f1
(
fileA
,
std
::
ifstream
::
binary
|
std
::
ifstream
::
ate
);
std
::
ifstream
f1
(
fileA
,
std
::
ifstream
::
binary
|
std
::
ifstream
::
ate
);
std
::
ifstream
f2
(
fileB
,
std
::
ifstream
::
binary
|
std
::
ifstream
::
ate
);
std
::
ifstream
f2
(
fileB
,
std
::
ifstream
::
binary
|
std
::
ifstream
::
ate
);
...
@@ -113,7 +115,8 @@ FileTransferTest::setUp()
...
@@ -113,7 +115,8 @@ FileTransferTest::setUp()
std
::
mutex
mtx
;
std
::
mutex
mtx
;
std
::
unique_lock
<
std
::
mutex
>
lk
{
mtx
};
std
::
unique_lock
<
std
::
mutex
>
lk
{
mtx
};
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
confHandlers
.
insert
(
DRing
::
exportable_callback
<
DRing
::
ConfigurationSignal
::
VolatileDetailsChanged
>
(
confHandlers
.
insert
(
DRing
::
exportable_callback
<
DRing
::
ConfigurationSignal
::
VolatileDetailsChanged
>
(
[
&
](
const
std
::
string
&
,
const
std
::
map
<
std
::
string
,
std
::
string
>&
)
{
[
&
](
const
std
::
string
&
,
const
std
::
map
<
std
::
string
,
std
::
string
>&
)
{
bool
ready
=
false
;
bool
ready
=
false
;
auto
details
=
aliceAccount
->
getVolatileAccountDetails
();
auto
details
=
aliceAccount
->
getVolatileAccountDetails
();
...
@@ -138,8 +141,8 @@ FileTransferTest::tearDown()
...
@@ -138,8 +141,8 @@ FileTransferTest::tearDown()
std
::
unique_lock
<
std
::
mutex
>
lk
{
mtx
};
std
::
unique_lock
<
std
::
mutex
>
lk
{
mtx
};
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
auto
currentAccSize
=
Manager
::
instance
().
getAccountList
().
size
();
auto
currentAccSize
=
Manager
::
instance
().
getAccountList
().
size
();
confHandlers
.
insert
(
DRing
::
exportable_callback
<
DRing
::
ConfigurationSignal
::
AccountsChanged
>
(
confHandlers
.
insert
(
[
&
]()
{
DRing
::
exportable_callback
<
DRing
::
ConfigurationSignal
::
AccountsChanged
>
(
[
&
]()
{
if
(
Manager
::
instance
().
getAccountList
().
size
()
<=
currentAccSize
-
2
)
{
if
(
Manager
::
instance
().
getAccountList
().
size
()
<=
currentAccSize
-
2
)
{
cv
.
notify_one
();
cv
.
notify_one
();
}
}
...
@@ -173,13 +176,13 @@ FileTransferTest::testCachedFileTransfer()
...
@@ -173,13 +176,13 @@ FileTransferTest::testCachedFileTransfer()
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
std
::
condition_variable
cv2
;
std
::
condition_variable
cv2
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
DRing
::
CallbackWrapperBase
>>
confHandlers
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
DRing
::
CallbackWrapperBase
>>
confHandlers
;
bool
transfer
Created
=
false
,
transferFinished
=
false
;
bool
transfer
Waiting
=
false
,
transferFinished
=
false
;
DRing
::
DataTransferId
finalId
;
DRing
::
DataTransferId
finalId
;
// Watch signals
// Watch signals
confHandlers
.
insert
(
DRing
::
exportable_callback
<
DRing
::
DataTransferSignal
::
DataTransferEvent
>
(
confHandlers
.
insert
(
DRing
::
exportable_callback
<
DRing
::
DataTransferSignal
::
DataTransferEvent
>
(
[
&
](
const
long
unsigned
int
&
id
,
int
code
)
{
[
&
](
const
long
unsigned
int
&
id
,
int
code
)
{
if
(
code
==
static_cast
<
int
>
(
DRing
::
DataTransferEventCode
::
created
))
{
if
(
code
==
static_cast
<
int
>
(
DRing
::
DataTransferEventCode
::
wait_host_acceptance
))
{
transfer
Created
=
true
;
transfer
Waiting
=
true
;
finalId
=
id
;
finalId
=
id
;
cv
.
notify_one
();
cv
.
notify_one
();
}
else
if
(
code
==
static_cast
<
int
>
(
DRing
::
DataTransferEventCode
::
finished
))
{
}
else
if
(
code
==
static_cast
<
int
>
(
DRing
::
DataTransferEventCode
::
finished
))
{
...
@@ -190,14 +193,6 @@ FileTransferTest::testCachedFileTransfer()
...
@@ -190,14 +193,6 @@ FileTransferTest::testCachedFileTransfer()
}));
}));
DRing
::
registerSignalHandlers
(
confHandlers
);
DRing
::
registerSignalHandlers
(
confHandlers
);
bool
successfullyReceive
=
false
;
bobAccount
->
connectionManager
().
onChannelRequest
(
[
&
successfullyReceive
,
&
cv
](
const
std
::
string
&
,
const
std
::
string
&
name
)
{
successfullyReceive
=
name
.
substr
(
0
,
7
)
==
"file://"
;
cv
.
notify_one
();
return
true
;
});
// Create file to send
// Create file to send
std
::
ofstream
sendFile
(
"SEND"
);
std
::
ofstream
sendFile
(
"SEND"
);
CPPUNIT_ASSERT
(
sendFile
.
is_open
());
CPPUNIT_ASSERT
(
sendFile
.
is_open
());
...
@@ -215,13 +210,11 @@ FileTransferTest::testCachedFileTransfer()
...
@@ -215,13 +210,11 @@ FileTransferTest::testCachedFileTransfer()
CPPUNIT_ASSERT
(
DRing
::
sendFile
(
info
,
id
)
==
DRing
::
DataTransferError
::
success
);
CPPUNIT_ASSERT
(
DRing
::
sendFile
(
info
,
id
)
==
DRing
::
DataTransferError
::
success
);
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
CPPUNIT_ASSERT
(
successfullyReceive
);
CPPUNIT_ASSERT
(
transferWaiting
);
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
CPPUNIT_ASSERT
(
transferCreated
);
auto
rcv_path
=
"RECV"
;
auto
rcv_path
=
"RECV"
;
CPPUNIT_ASSERT
(
DRing
::
acceptFileTransfer
(
finalId
,
rcv_path
,
0
)
==
DRing
::
DataTransferError
::
success
);
CPPUNIT_ASSERT
(
DRing
::
acceptFileTransfer
(
finalId
,
rcv_path
,
0
)
==
DRing
::
DataTransferError
::
success
);
// Wait 2 times, both sides will got a finished status
// Wait 2 times, both sides will got a finished status
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
...
@@ -257,13 +250,13 @@ FileTransferTest::testMultipleFileTransfer()
...
@@ -257,13 +250,13 @@ FileTransferTest::testMultipleFileTransfer()
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
std
::
condition_variable
cv2
;
std
::
condition_variable
cv2
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
DRing
::
CallbackWrapperBase
>>
confHandlers
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
DRing
::
CallbackWrapperBase
>>
confHandlers
;
bool
transfer
Created
=
false
,
transferFinished
=
false
;
bool
transfer
Waiting
=
false
,
transferFinished
=
false
;
DRing
::
DataTransferId
finalId
;
DRing
::
DataTransferId
finalId
;
// Watch signals
// Watch signals
confHandlers
.
insert
(
DRing
::
exportable_callback
<
DRing
::
DataTransferSignal
::
DataTransferEvent
>
(
confHandlers
.
insert
(
DRing
::
exportable_callback
<
DRing
::
DataTransferSignal
::
DataTransferEvent
>
(
[
&
](
const
long
unsigned
int
&
id
,
int
code
)
{
[
&
](
const
long
unsigned
int
&
id
,
int
code
)
{
if
(
code
==
static_cast
<
int
>
(
DRing
::
DataTransferEventCode
::
created
))
{
if
(
code
==
static_cast
<
int
>
(
DRing
::
DataTransferEventCode
::
wait_host_acceptance
))
{
transfer
Created
=
true
;
transfer
Waiting
=
true
;
finalId
=
id
;
finalId
=
id
;
cv
.
notify_one
();
cv
.
notify_one
();
}
else
if
(
code
==
static_cast
<
int
>
(
DRing
::
DataTransferEventCode
::
finished
))
{
}
else
if
(
code
==
static_cast
<
int
>
(
DRing
::
DataTransferEventCode
::
finished
))
{
...
@@ -274,14 +267,6 @@ FileTransferTest::testMultipleFileTransfer()
...
@@ -274,14 +267,6 @@ FileTransferTest::testMultipleFileTransfer()
}));
}));
DRing
::
registerSignalHandlers
(
confHandlers
);
DRing
::
registerSignalHandlers
(
confHandlers
);
bool
successfullyReceive
=
false
;
bobAccount
->
connectionManager
().
onChannelRequest
(
[
&
successfullyReceive
,
&
cv
](
const
std
::
string
&
,
const
std
::
string
&
name
)
{
successfullyReceive
=
name
.
substr
(
0
,
7
)
==
"file://"
;
cv
.
notify_one
();
return
true
;
});
// Create file to send
// Create file to send
std
::
ofstream
sendFile
(
"SEND"
);
std
::
ofstream
sendFile
(
"SEND"
);
CPPUNIT_ASSERT
(
sendFile
.
is_open
());
CPPUNIT_ASSERT
(
sendFile
.
is_open
());
...
@@ -303,13 +288,12 @@ FileTransferTest::testMultipleFileTransfer()
...
@@ -303,13 +288,12 @@ FileTransferTest::testMultipleFileTransfer()
CPPUNIT_ASSERT
(
DRing
::
sendFile
(
info
,
id
)
==
DRing
::
DataTransferError
::
success
);
CPPUNIT_ASSERT
(
DRing
::
sendFile
(
info
,
id
)
==
DRing
::
DataTransferError
::
success
);
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
CPPUNIT_ASSERT
(
successfullyReceive
);
CPPUNIT_ASSERT
(
transferWaiting
);
transferWaiting
=
false
;
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
CPPUNIT_ASSERT
(
transferCreated
);
auto
rcv_path
=
"RECV"
;
auto
rcv_path
=
"RECV"
;
CPPUNIT_ASSERT
(
DRing
::
acceptFileTransfer
(
finalId
,
rcv_path
,
0
)
==
DRing
::
DataTransferError
::
success
);
CPPUNIT_ASSERT
(
DRing
::
acceptFileTransfer
(
finalId
,
rcv_path
,
0
)
==
DRing
::
DataTransferError
::
success
);
// Wait 2 times, both sides will got a finished status
// Wait 2 times, both sides will got a finished status
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
...
@@ -328,13 +312,11 @@ FileTransferTest::testMultipleFileTransfer()
...
@@ -328,13 +312,11 @@ FileTransferTest::testMultipleFileTransfer()
CPPUNIT_ASSERT
(
DRing
::
sendFile
(
info2
,
id
)
==
DRing
::
DataTransferError
::
success
);
CPPUNIT_ASSERT
(
DRing
::
sendFile
(
info2
,
id
)
==
DRing
::
DataTransferError
::
success
);
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
CPPUNIT_ASSERT
(
successfullyReceive
);
CPPUNIT_ASSERT
(
transferWaiting
);
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
CPPUNIT_ASSERT
(
transferCreated
);
rcv_path
=
"RECV2"
;
rcv_path
=
"RECV2"
;
CPPUNIT_ASSERT
(
DRing
::
acceptFileTransfer
(
finalId
,
rcv_path
,
0
)
==
DRing
::
DataTransferError
::
success
);
CPPUNIT_ASSERT
(
DRing
::
acceptFileTransfer
(
finalId
,
rcv_path
,
0
)
==
DRing
::
DataTransferError
::
success
);
// Wait 2 times, both sides will got a finished status
// Wait 2 times, both sides will got a finished status
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
));
...
@@ -353,6 +335,7 @@ FileTransferTest::testMultipleFileTransfer()
...
@@ -353,6 +335,7 @@ FileTransferTest::testMultipleFileTransfer()
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
3
));
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
3
));
}
}
}}
// namespace test
}
// namespace test
}
// namespace jami
RING_TEST_RUNNER
(
jami
::
test
::
FileTransferTest
::
name
())
RING_TEST_RUNNER
(
jami
::
test
::
FileTransferTest
::
name
())
\ No newline at end of file
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