[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash/testsuite/misc-ming.all key_event_test.c ...
From: |
Zou Lunkai |
Subject: |
[Gnash-commit] gnash/testsuite/misc-ming.all key_event_test.c ... |
Date: |
Mon, 23 Apr 2007 11:15:38 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Zou Lunkai <zoulunkai> 07/04/23 11:15:38
Added files:
testsuite/misc-ming.all: key_event_test.c
key_event_testrunner.cpp
Log message:
testcase for key events
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/misc-ming.all/key_event_test.c?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/misc-ming.all/key_event_testrunner.cpp?cvsroot=gnash&rev=1.1
Patches:
Index: key_event_test.c
===================================================================
RCS file: key_event_test.c
diff -N key_event_test.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ key_event_test.c 23 Apr 2007 11:15:38 -0000 1.1
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/*
+ * Key events are: KeyUp, KeyDown, KeyPress
+ * (1)KeyUp and KeyDown event handler is unrelated to any key;
+ * (2)KeyPress event handler should bind a valid key, which is hard-coded in
the placement tag;
+ * (3)Use Key.addListener() to register user defined key event handler,
otherwise it will not
+ * be triggered.
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <ming.h>
+
+#include "ming_utils.h"
+
+#define OUTPUT_VERSION 6
+#define OUTPUT_FILENAME "key_event_test.swf"
+
+
+int
+main(int argc, char** argv)
+{
+ SWFMovie mo;
+ SWFMovieClip mc, dejagnuclip;
+ SWFDisplayItem it;
+ SWFShape sh_red;
+
+ const char *srcdir=".";
+ if ( argc>1 )
+ srcdir=argv[1];
+ else
+ {
+ fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
+ return 1;
+ }
+
+ Ming_init();
+ mo = newSWFMovieWithVersion(OUTPUT_VERSION);
+ SWFMovie_setDimension(mo, 800, 600);
+ SWFMovie_setRate (mo, 1.0);
+
+ dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0,
800, 600);
+ SWFMovie_add(mo, (SWFBlock)dejagnuclip);
+ add_actions(mo, "x1=0; x2=0; x3=0; x=0; x5=0; x6=0; ");
+ SWFMovie_nextFrame(mo); /* 1st frame */
+
+
+ mc = newSWFMovieClip();
+ sh_red = make_fill_square (300, 300, 60, 60, 255, 0, 0, 255, 0, 0);
+ SWFMovieClip_add(mc, (SWFBlock)sh_red);
+ SWFMovieClip_nextFrame(mc);
+
+
+ it = SWFMovie_add(mo, (SWFBlock)mc);
+ SWFDisplayItem_setDepth(it, 20);
+ SWFDisplayItem_setName(it, "mc");
+ /* Define onClipKeyDown */
+ SWFDisplayItem_addAction(it,
+ newSWFAction(" _root.x1 = Key.getAscii(); "
+ " _root.note('onClipKeyDown triggered'); "
+ " _root.note('key ASCII value: ' + _root.x1); "),
+ SWFACTION_KEYDOWN);
+ /* Define onClipKeyUp */
+ SWFDisplayItem_addAction(it,
+ newSWFAction(" _root.x2 = Key.getCode(); "
+ " _root.note('onClipKeyUp triggered'); "
+ " _root.note('key code: ' + _root.x2); "),
+ SWFACTION_KEYUP);
+ /* Define onClipKeyUp. Question: how to bind a key code with the KeyPress
event??? */
+ SWFDisplayItem_addAction(it,
+ newSWFAction(" _root.note('onClipKeyPress triggered'); "
+ " _root.x3 = _root.x1; "),
+ SWFACTION_KEYPRESS);
+
+ /* add user defined events */
+ add_actions(mo, " mc.onKeyDown = function () { "
+ " _root.x4 = Key.getAscii(); "
+ " _root.note('user defined onKeyDown triggered'); "
+ " _root.note('key ASCII value: ' + _root.x4); }; "
+
+ " mc.onKeyUp = function () { "
+ " _root.x5 = Key.getCode(); "
+ " _root.note('user defined onKeyUp triggered'); "
+ " _root.note('key code: ' + _root.x5); }; "
+
+ " mc.onKeyPress = function () { "
+ " _root.x6 = _root.x3; "
+ " _root.note('user defined onKeyPress triggered'); }; "
+ );
+
+ SWFMovie_nextFrame(mo); /* 2nd frame */
+
+ int frame_num = 3;
+ for(frame_num; frame_num<=30; frame_num++)
+ {
+ SWFMovie_nextFrame(mo);
+ }
+
+ add_actions(mo, "_root.note('mc registered by addListener()'); ");
+ /* register "mc" to receive onKeyDown and onKeyUp notification after 30
seconds(30 frames). */
+ add_actions(mo, " Key.addListener(mc); stop(); ");
+ SWFMovie_nextFrame(mo); /* 31th frame */
+
+
+ //Output movie
+ puts("Saving " OUTPUT_FILENAME );
+ SWFMovie_save(mo, OUTPUT_FILENAME);
+
+ return 0;
+}
+
+
Index: key_event_testrunner.cpp
===================================================================
RCS file: key_event_testrunner.cpp
diff -N key_event_testrunner.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ key_event_testrunner.cpp 23 Apr 2007 11:15:38 -0000 1.1
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ *
+ */
+
+#define INPUT_FILENAME "key_event_test.swf"
+
+#include "MovieTester.h"
+#include "sprite_instance.h"
+#include "character.h"
+#include "dlist.h"
+#include "container.h"
+#include "log.h"
+
+#include "check.h"
+#include <string>
+#include <cassert>
+
+using namespace gnash;
+using namespace std;
+
+int
+main(int /*argc*/, char** /*argv*/)
+{
+ string filename = string(INPUT_FILENAME);
+ MovieTester tester(filename);
+
+ gnash::LogFile& dbglogfile = gnash::LogFile::getDefaultInstance();
+ dbglogfile.setVerbosity(1);
+
+ sprite_instance* root = tester.getRootMovie();
+ assert(root);
+
+ check_equals(root->get_frame_count(), 31);
+ check_equals(root->get_current_frame(), 0);
+
+ tester.advance();
+ check_equals(root->get_current_frame(), 1);
+
+ character* mc = const_cast<character*>(tester.findDisplayItemByName(*root,
"mc"));
+ check(mc);
+
+ as_value tmp;
+
+ check(root->get_member("x1", &tmp));
+ check_equals(tmp.to_number(), 0);
+
+ // press key 'A' and checks
+ tester.pressKey(key::A);
+ tester.releaseKey(key::A);
+
+ // check that onClipKeyUp/KeyDown have been triggered
+ check(root->get_member("x1", &tmp));
+ xcheck_equals(tmp.to_string(), "A");
+ check(root->get_member("x2", &tmp));
+ xcheck_equals(tmp.to_number(), key::A);
+
+ // check that user defined onKeyUp/KeyDown are not triggered
+ check(root->get_member("x4", &tmp));
+ check_equals(tmp.to_number(), 0);
+ check(root->get_member("x5", &tmp));
+ check_equals(tmp.to_number(), 0);
+
+ for(int i=1; i<30; i++)
+ {
+ tester.advance();
+ }
+
+ check_equals(root->get_current_frame(), 30); // the 31th frame
+ check_equals(root->get_play_state(), sprite_instance::STOP);
+
+ // press key 'B' and checks
+ tester.pressKey(key::C);
+ tester.releaseKey(key::C);
+
+ // check that onClipKeyUp/KeyDown have been triggered
+ check(root->get_member("x1", &tmp));
+ xcheck_equals(tmp.to_string(), "C");
+ check(root->get_member("x2", &tmp));
+ xcheck_equals(tmp.to_number(), key::C);
+
+ // check that user defined onKeyUp/KeyDown have been triggered
+ check(root->get_member("x4", &tmp));
+ check_equals(tmp.to_string(), "C");
+ check(root->get_member("x5", &tmp));
+ check_equals(tmp.to_number(), key::C);
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash/testsuite/misc-ming.all key_event_test.c ...,
Zou Lunkai <=