aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2007-05-19 11:18:44 (GMT)
committerfluxgen <fluxgen>2007-05-19 11:18:44 (GMT)
commitcf9c58bb0bbf80fb0f192e7c145ff851d4ca9050 (patch)
treee956c1c885f97ed5a9bbe3613811a84439bfe206
parent0f23536effc48781644c2548d9bb4f14aa149ce6 (diff)
downloadfluxbox-cf9c58bb0bbf80fb0f192e7c145ff851d4ca9050.zip
fluxbox-cf9c58bb0bbf80fb0f192e7c145ff851d4ca9050.tar.bz2
added title test for _NET_WM_NAME and WM_NAME memory leaks
-rw-r--r--src/tests/Makefile3
-rw-r--r--src/tests/titletest.cc120
2 files changed, 123 insertions, 0 deletions
diff --git a/src/tests/Makefile b/src/tests/Makefile
index e39ab0b..74fd97b 100644
--- a/src/tests/Makefile
+++ b/src/tests/Makefile
@@ -24,6 +24,9 @@ testKeys: testKeys.o
24testResource: Resourcetest.o Resource.o 24testResource: Resourcetest.o Resource.o
25 ${CXX} ${LIBS} ${XLIBS} Resourcetest.o Resource.o -o testResource 25 ${CXX} ${LIBS} ${XLIBS} Resourcetest.o Resource.o -o testResource
26 26
27testTitle: titletest.cc
28 ${CXX} ${CXXFLAGS} ${LIBS} ${XLIBS} titletest.cc ../FbTk/libFbTk.a -o testTitle
29
27signaltest: 30signaltest:
28 ${COMPILE} ../FbTk/SignalHandler.o signaltest.cc -o signaltest 31 ${COMPILE} ../FbTk/SignalHandler.o signaltest.cc -o signaltest
29 32
diff --git a/src/tests/titletest.cc b/src/tests/titletest.cc
new file mode 100644
index 0000000..a473d06
--- /dev/null
+++ b/src/tests/titletest.cc
@@ -0,0 +1,120 @@
1// titletest.cc for fbtk test suite
2// Copyright (c) 2007 Henrik Kinnunen (fluxgen at fluxbox dot org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id$
23
24#include "App.hh"
25#include "FbWindow.hh"
26#include "Font.hh"
27#include "EventHandler.hh"
28#include "EventManager.hh"
29#include "Timer.hh"
30#include "SimpleCommand.hh"
31#include "stringstream.hh"
32#include "GContext.hh"
33#include "Color.hh"
34
35#include <X11/Xutil.h>
36#include <X11/keysym.h>
37
38#include <string>
39#include <iostream>
40using namespace std;
41
42class App:public FbTk::App, public FbTk::EventHandler {
43public:
44 App(const char *displayname):
45 FbTk::App(displayname),
46 m_win(DefaultScreen(display()),
47 0, 0, 640, 100, KeyPressMask | ExposureMask |
48 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),
49 m_tick( 0 ) {
50
51 m_win.show();
52 m_win.setBackgroundColor(FbTk::Color("white", m_win.screenNumber()));
53 FbTk::EventManager::instance()->add(*this, m_win);
54 FbTk::RefCount<FbTk::Command> cmd(new FbTk::SimpleCommand<App>
55 (*this,
56 &App::updateTitle));
57 timeval t;
58 t.tv_sec = 0;
59 t.tv_usec = 150000;
60 m_timer.setTimeout(t);
61 m_timer.setCommand(cmd);
62 m_timer.fireOnce(false);
63 m_timer.start();
64
65 updateTitle();
66 m_win.clear();
67 srand( time( 0 ) );
68 }
69
70 ~App() {
71 }
72 void eventLoop() {
73 XEvent ev;
74 while (!done()) {
75 if (XPending(display())) {
76 XNextEvent(display(), &ev);
77 FbTk::EventManager::instance()->handleEvent(ev);
78 } else {
79 FbTk::Timer::updateTimers(ConnectionNumber(display()));
80 }
81 }
82 }
83
84 void updateTitle() {
85 FbTk_ostringstream str;
86 ++m_tick;
87 for (int i = 0, n = rand( ) % 10; i < max( 1, n ); ++i) {
88 str << " Tick #" << m_tick;
89 }
90
91 m_win.setName( str.str().c_str() );
92 // set _NET_WM_NAME
93 Atom net_wm_name = XInternAtom(display(), "_NET_WM_NAME", False);
94 Atom utf8_string = XInternAtom(display(), "UTF8_STRING", False);
95 XChangeProperty(display(), m_win.window(),
96 net_wm_name, utf8_string, 8,
97 PropModeReplace,
98 (unsigned char*)str.str().c_str(), str.str().size() );
99 }
100
101
102private:
103 FbTk::FbWindow m_win;
104 FbTk::Timer m_timer;
105 unsigned int m_tick;
106};
107
108int main(int argc, char **argv) {
109 string displayname("");
110 for (int a=1; a<argc; ++a) {
111 if (strcmp("-display", argv[a]) == 0 && a + 1 < argc) {
112 displayname = argv[++a];
113 }
114 }
115
116 App app(displayname.c_str());
117
118 app.eventLoop();
119
120}