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
c6147353
Commit
c6147353
authored
1 month ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
namedirectory: fix tests
GitLab:
#1100
Change-Id: I6ae6d125c730fc9a8a2125b9b6da68c005922bce
parent
39a92daa
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/unitTest/namedirectory/namedirectory.cpp
+33
-10
33 additions, 10 deletions
test/unitTest/namedirectory/namedirectory.cpp
with
33 additions
and
10 deletions
test/unitTest/namedirectory/namedirectory.cpp
+
33
−
10
View file @
c6147353
...
@@ -71,7 +71,15 @@ public:
...
@@ -71,7 +71,15 @@ public:
R"(/name/:name)"
,
R"(/name/:name)"
,
[](
auto
req
,
auto
params
)
{
[](
auto
req
,
auto
params
)
{
const
auto
qp
=
parse_query
(
req
->
header
().
query
());
const
auto
qp
=
parse_query
(
req
->
header
().
query
());
if
(
params
[
"name"
]
==
"taken"
)
{
const
auto
&
name
=
params
[
"name"
];
if
(
name
.
find
(
'%'
)
!=
std
::
string
::
npos
)
{
return
req
->
create_response
(
restinio
::
status_bad_request
())
.
set_body
(
fmt
::
format
(
"{{
\"
error
\"
:
\"
invalid name
\"
}}"
)
)
.
done
();
}
else
if
(
name
==
"taken"
)
{
return
req
->
create_response
()
return
req
->
create_response
()
.
set_body
(
.
set_body
(
fmt
::
format
(
"{{
\"
name
\"
:
\"
taken
\"
,
\"
addr
\"
:
\"
c0dec0dec0dec0dec0dec0dec0dec0dec0dec0de
\"
}}"
)
fmt
::
format
(
"{{
\"
name
\"
:
\"
taken
\"
,
\"
addr
\"
:
\"
c0dec0dec0dec0dec0dec0dec0dec0dec0dec0de
\"
}}"
)
...
@@ -88,7 +96,15 @@ public:
...
@@ -88,7 +96,15 @@ public:
R"(/addr/:addr)"
,
R"(/addr/:addr)"
,
[](
auto
req
,
auto
params
)
{
[](
auto
req
,
auto
params
)
{
const
auto
qp
=
parse_query
(
req
->
header
().
query
());
const
auto
qp
=
parse_query
(
req
->
header
().
query
());
if
(
params
[
"addr"
]
==
"c0dec0dec0dec0dec0dec0dec0dec0dec0dec0de"
)
{
const
auto
&
addr
=
params
[
"addr"
];
if
(
addr
.
find_first_not_of
(
"0123456789abcdefABCDEF"
)
!=
std
::
string
::
npos
)
{
return
req
->
create_response
(
restinio
::
status_bad_request
())
.
set_body
(
fmt
::
format
(
"{{
\"
error
\"
:
\"
invalid address
\"
}}"
)
)
.
done
();
}
else
if
(
addr
==
"c0dec0dec0dec0dec0dec0dec0dec0dec0dec0de"
)
{
return
req
->
create_response
()
return
req
->
create_response
()
.
set_body
(
.
set_body
(
fmt
::
format
(
"{{
\"
name
\"
:
\"
taken
\"
,
\"
addr
\"
:
\"
c0dec0dec0dec0dec0dec0dec0dec0dec0dec0de
\"
}}"
)
fmt
::
format
(
"{{
\"
name
\"
:
\"
taken
\"
,
\"
addr
\"
:
\"
c0dec0dec0dec0dec0dec0dec0dec0dec0dec0de
\"
}}"
)
...
@@ -183,7 +199,6 @@ void
...
@@ -183,7 +199,6 @@ void
NameDirectoryTest
::
testRegisterName
()
NameDirectoryTest
::
testRegisterName
()
{
{
std
::
mutex
mtx
;
std
::
mutex
mtx
;
std
::
unique_lock
lk
{
mtx
};
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
bool
nameRegistered
{
false
};
bool
nameRegistered
{
false
};
...
@@ -192,11 +207,13 @@ NameDirectoryTest::testRegisterName()
...
@@ -192,11 +207,13 @@ NameDirectoryTest::testRegisterName()
[
&
](
const
std
::
string
&
,
[
&
](
const
std
::
string
&
,
int
status
,
int
status
,
const
std
::
string
&
)
{
const
std
::
string
&
)
{
std
::
lock_guard
lk
{
mtx
};
nameRegistered
=
status
==
0
;
nameRegistered
=
status
==
0
;
cv
.
notify_one
();
cv
.
notify_one
();
}));
}));
libjami
::
registerSignalHandlers
(
confHandlers
);
libjami
::
registerSignalHandlers
(
confHandlers
);
CPPUNIT_ASSERT
(
libjami
::
registerName
(
aliceId
,
"foo"
));
CPPUNIT_ASSERT
(
libjami
::
registerName
(
aliceId
,
"foo"
));
std
::
unique_lock
lk
{
mtx
};
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
nameRegistered
;
}));
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
nameRegistered
;
}));
}
}
...
@@ -204,7 +221,6 @@ void
...
@@ -204,7 +221,6 @@ void
NameDirectoryTest
::
testLookupName
()
NameDirectoryTest
::
testLookupName
()
{
{
std
::
mutex
mtx
;
std
::
mutex
mtx
;
std
::
unique_lock
lk
{
mtx
};
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
bool
nameFound
{
false
};
bool
nameFound
{
false
};
...
@@ -215,11 +231,13 @@ NameDirectoryTest::testLookupName()
...
@@ -215,11 +231,13 @@ NameDirectoryTest::testLookupName()
int
status
,
int
status
,
const
std
::
string
&
,
const
std
::
string
&
,
const
std
::
string
&
)
{
const
std
::
string
&
)
{
std
::
lock_guard
lk
{
mtx
};
nameFound
=
status
==
0
;
nameFound
=
status
==
0
;
cv
.
notify_one
();
cv
.
notify_one
();
}));
}));
libjami
::
registerSignalHandlers
(
confHandlers
);
libjami
::
registerSignalHandlers
(
confHandlers
);
CPPUNIT_ASSERT
(
libjami
::
lookupName
(
aliceId
,
""
,
"taken"
));
CPPUNIT_ASSERT
(
libjami
::
lookupName
(
aliceId
,
""
,
"taken"
));
std
::
unique_lock
lk
{
mtx
};
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
nameFound
;
}));
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
nameFound
;
}));
}
}
...
@@ -227,7 +245,6 @@ void
...
@@ -227,7 +245,6 @@ void
NameDirectoryTest
::
testLookupNameInvalid
()
NameDirectoryTest
::
testLookupNameInvalid
()
{
{
std
::
mutex
mtx
;
std
::
mutex
mtx
;
std
::
unique_lock
lk
{
mtx
};
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
bool
nameInvalid
{
false
};
bool
nameInvalid
{
false
};
...
@@ -238,11 +255,13 @@ NameDirectoryTest::testLookupNameInvalid()
...
@@ -238,11 +255,13 @@ NameDirectoryTest::testLookupNameInvalid()
int
status
,
int
status
,
const
std
::
string
&
,
const
std
::
string
&
,
const
std
::
string
&
)
{
const
std
::
string
&
)
{
std
::
lock_guard
lk
{
mtx
};
nameInvalid
=
status
==
1
;
nameInvalid
=
status
==
1
;
cv
.
notify_one
();
cv
.
notify_one
();
}));
}));
libjami
::
registerSignalHandlers
(
confHandlers
);
libjami
::
registerSignalHandlers
(
confHandlers
);
CPPUNIT_ASSERT
(
libjami
::
lookupName
(
aliceId
,
""
,
"===="
));
CPPUNIT_ASSERT
(
libjami
::
lookupName
(
aliceId
,
""
,
"===="
));
std
::
unique_lock
lk
{
mtx
};
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
nameInvalid
;
}));
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
nameInvalid
;
}));
}
}
...
@@ -250,7 +269,6 @@ void
...
@@ -250,7 +269,6 @@ void
NameDirectoryTest
::
testLookupNameNotFound
()
NameDirectoryTest
::
testLookupNameNotFound
()
{
{
std
::
mutex
mtx
;
std
::
mutex
mtx
;
std
::
unique_lock
lk
{
mtx
};
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
bool
nameNotFound
{
false
};
bool
nameNotFound
{
false
};
...
@@ -261,11 +279,13 @@ NameDirectoryTest::testLookupNameNotFound()
...
@@ -261,11 +279,13 @@ NameDirectoryTest::testLookupNameNotFound()
int
status
,
int
status
,
const
std
::
string
&
,
const
std
::
string
&
,
const
std
::
string
&
)
{
const
std
::
string
&
)
{
std
::
lock_guard
lk
{
mtx
};
nameNotFound
=
status
==
2
;
nameNotFound
=
status
==
2
;
cv
.
notify_one
();
cv
.
notify_one
();
}));
}));
libjami
::
registerSignalHandlers
(
confHandlers
);
libjami
::
registerSignalHandlers
(
confHandlers
);
CPPUNIT_ASSERT
(
libjami
::
lookupName
(
aliceId
,
""
,
"nottaken"
));
CPPUNIT_ASSERT
(
libjami
::
lookupName
(
aliceId
,
""
,
"nottaken"
));
std
::
unique_lock
lk
{
mtx
};
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
nameNotFound
;
}));
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
nameNotFound
;
}));
}
}
...
@@ -273,7 +293,6 @@ void
...
@@ -273,7 +293,6 @@ void
NameDirectoryTest
::
testLookupAddr
()
NameDirectoryTest
::
testLookupAddr
()
{
{
std
::
mutex
mtx
;
std
::
mutex
mtx
;
std
::
unique_lock
lk
{
mtx
};
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
bool
addrFound
{
false
};
bool
addrFound
{
false
};
...
@@ -284,11 +303,13 @@ NameDirectoryTest::testLookupAddr()
...
@@ -284,11 +303,13 @@ NameDirectoryTest::testLookupAddr()
int
status
,
int
status
,
const
std
::
string
&
,
const
std
::
string
&
,
const
std
::
string
&
)
{
const
std
::
string
&
)
{
std
::
lock_guard
lk
{
mtx
};
addrFound
=
status
==
0
;
addrFound
=
status
==
0
;
cv
.
notify_one
();
cv
.
notify_one
();
}));
}));
libjami
::
registerSignalHandlers
(
confHandlers
);
libjami
::
registerSignalHandlers
(
confHandlers
);
CPPUNIT_ASSERT
(
libjami
::
lookupAddress
(
aliceId
,
""
,
"c0dec0dec0dec0dec0dec0dec0dec0dec0dec0de"
));
CPPUNIT_ASSERT
(
libjami
::
lookupAddress
(
aliceId
,
""
,
"c0dec0dec0dec0dec0dec0dec0dec0dec0dec0de"
));
std
::
unique_lock
lk
{
mtx
};
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
addrFound
;
}));
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
addrFound
;
}));
}
}
...
@@ -296,7 +317,6 @@ void
...
@@ -296,7 +317,6 @@ void
NameDirectoryTest
::
testLookupAddrInvalid
()
NameDirectoryTest
::
testLookupAddrInvalid
()
{
{
std
::
mutex
mtx
;
std
::
mutex
mtx
;
std
::
unique_lock
lk
{
mtx
};
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
bool
addrInvalid
{
false
};
bool
addrInvalid
{
false
};
...
@@ -307,11 +327,13 @@ NameDirectoryTest::testLookupAddrInvalid()
...
@@ -307,11 +327,13 @@ NameDirectoryTest::testLookupAddrInvalid()
int
status
,
int
status
,
const
std
::
string
&
,
const
std
::
string
&
,
const
std
::
string
&
)
{
const
std
::
string
&
)
{
std
::
lock_guard
lk
{
mtx
};
addrInvalid
=
status
==
1
;
addrInvalid
=
status
==
1
;
cv
.
notify_one
();
cv
.
notify_one
();
}));
}));
libjami
::
registerSignalHandlers
(
confHandlers
);
libjami
::
registerSignalHandlers
(
confHandlers
);
CPPUNIT_ASSERT
(
libjami
::
lookupName
(
aliceId
,
""
,
"===="
));
CPPUNIT_ASSERT
(
libjami
::
lookupAddress
(
aliceId
,
""
,
"===="
));
std
::
unique_lock
lk
{
mtx
};
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
addrInvalid
;
}));
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
addrInvalid
;
}));
}
}
...
@@ -319,7 +341,6 @@ void
...
@@ -319,7 +341,6 @@ void
NameDirectoryTest
::
testLookupAddrNotFound
()
NameDirectoryTest
::
testLookupAddrNotFound
()
{
{
std
::
mutex
mtx
;
std
::
mutex
mtx
;
std
::
unique_lock
lk
{
mtx
};
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
libjami
::
CallbackWrapperBase
>>
confHandlers
;
bool
addrNotFound
{
false
};
bool
addrNotFound
{
false
};
...
@@ -330,11 +351,13 @@ NameDirectoryTest::testLookupAddrNotFound()
...
@@ -330,11 +351,13 @@ NameDirectoryTest::testLookupAddrNotFound()
int
status
,
int
status
,
const
std
::
string
&
,
const
std
::
string
&
,
const
std
::
string
&
)
{
const
std
::
string
&
)
{
std
::
lock_guard
lk
{
mtx
};
addrNotFound
=
status
==
2
;
addrNotFound
=
status
==
2
;
cv
.
notify_one
();
cv
.
notify_one
();
}));
}));
libjami
::
registerSignalHandlers
(
confHandlers
);
libjami
::
registerSignalHandlers
(
confHandlers
);
CPPUNIT_ASSERT
(
libjami
::
lookupAddress
(
aliceId
,
""
,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
));
CPPUNIT_ASSERT
(
libjami
::
lookupAddress
(
aliceId
,
""
,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
));
std
::
unique_lock
lk
{
mtx
};
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
addrNotFound
;
}));
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]
{
return
addrNotFound
;
}));
}
}
...
...
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