Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Alchemy Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Silent mode is enabled
All outbound communications are blocked.
Learn more
.
Show more breadcrumbs
Alchemy Viewer
Alchemy Viewer
Commits
5afffabc
Commit
5afffabc
authored
13 years ago
by
Logan Dethrow
Browse files
Options
Downloads
Patches
Plain Diff
Backed out changeset 19aa1a773410
parent
ec065bdf
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
indra/test/CMakeLists.txt
+1
-1
1 addition, 1 deletion
indra/test/CMakeLists.txt
indra/test/llevents_tut.cpp
+47
-117
47 additions, 117 deletions
indra/test/llevents_tut.cpp
with
48 additions
and
118 deletions
indra/test/CMakeLists.txt
+
1
−
1
View file @
5afffabc
This diff is collapsed.
Click to expand it.
indra/test/llevents_tut.cpp
+
47
−
117
View file @
5afffabc
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
* $/LicenseInfo$
*/
*/
#if LL_WINDOWS
#if LL_WINDOWS
#pragma warning (disable : 4675) // "resolved by ADL" -- just as I want!
#pragma warning (disable : 4675) // "resolved by ADL" -- just as I want!
#endif
#endif
...
@@ -37,6 +38,7 @@
...
@@ -37,6 +38,7 @@
#define testable public
#define testable public
#include
"llevents.h"
#include
"llevents.h"
#undef testable
#undef testable
#include
"lllistenerwrapper.h"
// STL headers
// STL headers
// std headers
// std headers
#include
<iostream>
#include
<iostream>
...
@@ -48,96 +50,10 @@
...
@@ -48,96 +50,10 @@
// other Linden headers
// other Linden headers
#include
"lltut.h"
#include
"lltut.h"
#include
"stringize.h"
#include
"stringize.h"
#include
"tests/listener.h"
using
boost
::
assign
::
list_of
;
using
boost
::
assign
::
list_of
;
/*****************************************************************************
* test listener class
*****************************************************************************/
class
Listener
;
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
Listener
&
);
class
Listener
{
public:
Listener
(
const
std
::
string
&
name
)
:
mName
(
name
)
{
// std::cout << *this << ": ctor\n";
}
Listener
(
const
Listener
&
that
)
:
mName
(
that
.
mName
),
mLastEvent
(
that
.
mLastEvent
)
{
// std::cout << *this << ": copy\n";
}
virtual
~
Listener
()
{
// std::cout << *this << ": dtor\n";
}
std
::
string
getName
()
const
{
return
mName
;
}
bool
call
(
const
LLSD
&
event
)
{
// std::cout << *this << "::call(" << event << ")\n";
mLastEvent
=
event
;
return
false
;
}
bool
callstop
(
const
LLSD
&
event
)
{
// std::cout << *this << "::callstop(" << event << ")\n";
mLastEvent
=
event
;
return
true
;
}
LLSD
getLastEvent
()
const
{
// std::cout << *this << "::getLastEvent() -> " << mLastEvent << "\n";
return
mLastEvent
;
}
void
reset
(
const
LLSD
&
to
=
LLSD
())
{
// std::cout << *this << "::reset(" << to << ")\n";
mLastEvent
=
to
;
}
private
:
std
::
string
mName
;
LLSD
mLastEvent
;
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Listener
&
listener
)
{
out
<<
"Listener("
<<
listener
.
getName
()
/* << "@" << &listener */
<<
')'
;
return
out
;
}
struct
Collect
{
bool
add
(
const
std
::
string
&
bound
,
const
LLSD
&
event
)
{
result
.
push_back
(
bound
);
return
false
;
}
void
clear
()
{
result
.
clear
();
}
typedef
std
::
vector
<
std
::
string
>
StringList
;
StringList
result
;
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Collect
::
StringList
&
strings
)
{
out
<<
'('
;
Collect
::
StringList
::
const_iterator
begin
(
strings
.
begin
()),
end
(
strings
.
end
());
if
(
begin
!=
end
)
{
out
<<
'"'
<<
*
begin
<<
'"'
;
while
(
++
begin
!=
end
)
{
out
<<
",
\"
"
<<
*
begin
<<
'"'
;
}
}
out
<<
')'
;
return
out
;
}
template
<
typename
T
>
template
<
typename
T
>
T
make
(
const
T
&
value
)
{
return
value
;
}
T
make
(
const
T
&
value
)
{
return
value
;
}
...
@@ -190,14 +106,7 @@ namespace tut
...
@@ -190,14 +106,7 @@ namespace tut
// default combiner is defined to return the value returned by the
// default combiner is defined to return the value returned by the
// last listener, which is meaningless if there were no listeners.
// last listener, which is meaningless if there were no listeners.
per_frame
.
post
(
0
);
per_frame
.
post
(
0
);
// NOTE: boost::bind() saves its arguments by VALUE! If you pass an
LLBoundListener
connection
=
listener0
.
listenTo
(
per_frame
);
// object instance rather than a pointer, you'll end up binding to an
// internal copy of that instance! Use boost::ref() to capture a
// reference instead.
LLBoundListener
connection
=
per_frame
.
listen
(
listener0
.
getName
(),
boost
::
bind
(
&
Listener
::
call
,
boost
::
ref
(
listener0
),
_1
));
ensure
(
"connected"
,
connection
.
connected
());
ensure
(
"connected"
,
connection
.
connected
());
ensure
(
"not blocked"
,
!
connection
.
blocked
());
ensure
(
"not blocked"
,
!
connection
.
blocked
());
per_frame
.
post
(
1
);
per_frame
.
post
(
1
);
...
@@ -223,6 +132,10 @@ namespace tut
...
@@ -223,6 +132,10 @@ namespace tut
bool
threw
=
false
;
bool
threw
=
false
;
try
try
{
{
// NOTE: boost::bind() saves its arguments by VALUE! If you pass
// an object instance rather than a pointer, you'll end up binding
// to an internal copy of that instance! Use boost::ref() to
// capture a reference instead.
per_frame
.
listen
(
listener0
.
getName
(),
// note bug, dup name
per_frame
.
listen
(
listener0
.
getName
(),
// note bug, dup name
boost
::
bind
(
&
Listener
::
call
,
boost
::
ref
(
listener1
),
_1
));
boost
::
bind
(
&
Listener
::
call
,
boost
::
ref
(
listener1
),
_1
));
}
}
...
@@ -237,8 +150,7 @@ namespace tut
...
@@ -237,8 +150,7 @@ namespace tut
}
}
ensure
(
"threw DupListenerName"
,
threw
);
ensure
(
"threw DupListenerName"
,
threw
);
// do it right this time
// do it right this time
per_frame
.
listen
(
listener1
.
getName
(),
listener1
.
listenTo
(
per_frame
);
boost
::
bind
(
&
Listener
::
call
,
boost
::
ref
(
listener1
),
_1
));
per_frame
.
post
(
5
);
per_frame
.
post
(
5
);
check_listener
(
"got"
,
listener0
,
5
);
check_listener
(
"got"
,
listener0
,
5
);
check_listener
(
"got"
,
listener1
,
5
);
check_listener
(
"got"
,
listener1
,
5
);
...
@@ -268,14 +180,8 @@ namespace tut
...
@@ -268,14 +180,8 @@ namespace tut
LLEventPump
&
per_frame
(
pumps
.
obtain
(
"per-frame"
));
LLEventPump
&
per_frame
(
pumps
.
obtain
(
"per-frame"
));
listener0
.
reset
(
0
);
listener0
.
reset
(
0
);
listener1
.
reset
(
0
);
listener1
.
reset
(
0
);
LLBoundListener
bound0
=
per_frame
.
listen
(
listener0
.
getName
(),
LLBoundListener
bound0
=
listener0
.
listenTo
(
per_frame
,
&
Listener
::
callstop
);
boost
::
bind
(
&
Listener
::
callstop
,
LLBoundListener
bound1
=
listener1
.
listenTo
(
per_frame
,
&
Listener
::
call
,
boost
::
ref
(
listener0
),
_1
));
LLBoundListener
bound1
=
per_frame
.
listen
(
listener1
.
getName
(),
boost
::
bind
(
&
Listener
::
call
,
boost
::
ref
(
listener1
),
_1
),
// after listener0
// after listener0
make
<
LLEventPump
::
NameList
>
(
list_of
(
listener0
.
getName
())));
make
<
LLEventPump
::
NameList
>
(
list_of
(
listener0
.
getName
())));
ensure
(
"enabled"
,
per_frame
.
enabled
());
ensure
(
"enabled"
,
per_frame
.
enabled
());
...
@@ -317,7 +223,7 @@ namespace tut
...
@@ -317,7 +223,7 @@ namespace tut
// LLEventQueue.
// LLEventQueue.
LLEventPump
&
mainloop
(
pumps
.
obtain
(
"mainloop"
));
LLEventPump
&
mainloop
(
pumps
.
obtain
(
"mainloop"
));
ensure
(
"LLEventQueue leaf class"
,
dynamic_cast
<
LLEventQueue
*>
(
&
login
));
ensure
(
"LLEventQueue leaf class"
,
dynamic_cast
<
LLEventQueue
*>
(
&
login
));
l
ogin
.
listen
(
listener0
.
getName
(),
boost
::
bind
(
&
Listener
::
call
,
boost
::
ref
(
listener0
),
_1
)
);
l
istener0
.
listenTo
(
login
);
listener0
.
reset
(
0
);
listener0
.
reset
(
0
);
login
.
post
(
1
);
login
.
post
(
1
);
check_listener
(
"waiting for queued event"
,
listener0
,
0
);
check_listener
(
"waiting for queued event"
,
listener0
,
0
);
...
@@ -370,11 +276,10 @@ namespace tut
...
@@ -370,11 +276,10 @@ namespace tut
{
{
set_test_name
(
"stopListening()"
);
set_test_name
(
"stopListening()"
);
LLEventPump
&
login
(
pumps
.
obtain
(
"login"
));
LLEventPump
&
login
(
pumps
.
obtain
(
"login"
));
l
ogin
.
listen
(
listener0
.
getName
(),
boost
::
bind
(
&
Listener
::
call
,
boost
::
ref
(
listener0
),
_1
)
);
l
istener0
.
listenTo
(
login
);
login
.
stopListening
(
listener0
.
getName
());
login
.
stopListening
(
listener0
.
getName
());
// should not throw because stopListening() should have removed name
// should not throw because stopListening() should have removed name
login
.
listen
(
listener0
.
getName
(),
listener0
.
listenTo
(
login
,
&
Listener
::
callstop
);
boost
::
bind
(
&
Listener
::
callstop
,
boost
::
ref
(
listener0
),
_1
));
LLBoundListener
wrong
=
login
.
getListener
(
"bogus"
);
LLBoundListener
wrong
=
login
.
getListener
(
"bogus"
);
ensure
(
"bogus connection disconnected"
,
!
wrong
.
connected
());
ensure
(
"bogus connection disconnected"
,
!
wrong
.
connected
());
ensure
(
"bogus connection blocked"
,
wrong
.
blocked
());
ensure
(
"bogus connection blocked"
,
wrong
.
blocked
());
...
@@ -394,10 +299,8 @@ namespace tut
...
@@ -394,10 +299,8 @@ namespace tut
boost
::
bind
(
&
LLEventPump
::
post
,
boost
::
ref
(
filter0
),
_1
));
boost
::
bind
(
&
LLEventPump
::
post
,
boost
::
ref
(
filter0
),
_1
));
upstream
.
listen
(
filter1
.
getName
(),
upstream
.
listen
(
filter1
.
getName
(),
boost
::
bind
(
&
LLEventPump
::
post
,
boost
::
ref
(
filter1
),
_1
));
boost
::
bind
(
&
LLEventPump
::
post
,
boost
::
ref
(
filter1
),
_1
));
filter0
.
listen
(
listener0
.
getName
(),
listener0
.
listenTo
(
filter0
);
boost
::
bind
(
&
Listener
::
call
,
boost
::
ref
(
listener0
),
_1
));
listener1
.
listenTo
(
filter1
);
filter1
.
listen
(
listener1
.
getName
(),
boost
::
bind
(
&
Listener
::
call
,
boost
::
ref
(
listener1
),
_1
));
listener0
.
reset
(
0
);
listener0
.
reset
(
0
);
listener1
.
reset
(
0
);
listener1
.
reset
(
0
);
upstream
.
post
(
1
);
upstream
.
post
(
1
);
...
@@ -552,7 +455,7 @@ namespace tut
...
@@ -552,7 +455,7 @@ namespace tut
// Passing a string LLEventPump name to LLListenerOrPumpName
// Passing a string LLEventPump name to LLListenerOrPumpName
listener0
.
reset
(
0
);
listener0
.
reset
(
0
);
LLEventStream
random
(
"random"
);
LLEventStream
random
(
"random"
);
random
.
listen
(
listener0
.
getName
(),
boost
::
bind
(
&
Listener
::
call
,
boost
::
ref
(
listener0
),
_1
)
);
listener0
.
listenTo
(
random
);
eventSource
(
"random"
);
eventSource
(
"random"
);
check_listener
(
"got by pump name"
,
listener0
,
17
);
check_listener
(
"got by pump name"
,
listener0
,
17
);
bool
threw
=
false
;
bool
threw
=
false
;
...
@@ -754,6 +657,33 @@ namespace tut
...
@@ -754,6 +657,33 @@ namespace tut
heaptest
.
post
(
2
);
heaptest
.
post
(
2
);
}
}
template
<
>
template
<
>
void
events_object
::
test
<
15
>
()
{
// This test ensures that using an LLListenerWrapper subclass doesn't
// block Boost.Signals2 from recognizing a bound LLEventTrackable
// subclass.
set_test_name
(
"listen(llwrap<LLLogListener>(boost::bind(...TempTrackableListener ref...)))"
);
bool
live
=
false
;
LLEventPump
&
heaptest
(
pumps
.
obtain
(
"heaptest"
));
LLBoundListener
connection
;
{
TempTrackableListener
tempListener
(
"temp"
,
live
);
ensure
(
"TempTrackableListener constructed"
,
live
);
connection
=
heaptest
.
listen
(
tempListener
.
getName
(),
llwrap
<
LLLogListener
>
(
boost
::
bind
(
&
TempTrackableListener
::
call
,
boost
::
ref
(
tempListener
),
_1
)));
heaptest
.
post
(
1
);
check_listener
(
"received"
,
tempListener
,
1
);
}
// presumably this will make tempListener go away?
// verify that
ensure
(
"TempTrackableListener destroyed"
,
!
live
);
ensure
(
"implicit disconnect"
,
!
connection
.
connected
());
// now just make sure we don't blow up trying to access a freed object!
heaptest
.
post
(
2
);
}
class
TempSharedListener
:
public
TempListener
,
class
TempSharedListener
:
public
TempListener
,
public
boost
::
enable_shared_from_this
<
TempSharedListener
>
public
boost
::
enable_shared_from_this
<
TempSharedListener
>
{
{
...
@@ -764,7 +694,7 @@ namespace tut
...
@@ -764,7 +694,7 @@ namespace tut
};
};
template
<
>
template
<
>
template
<
>
template
<
>
void
events_object
::
test
<
1
5
>
()
void
events_object
::
test
<
1
6
>
()
{
{
set_test_name
(
"listen(boost::bind(...TempSharedListener ref...))"
);
set_test_name
(
"listen(boost::bind(...TempSharedListener ref...))"
);
#if 0
#if 0
...
...
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