Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » C tools test cases
C tools test cases [message #457855] Sat, 01 August 2009 22:36 Go to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
Here are a couple of tests that I added for C with the mingw cdt tools
installed. These are similar to your java examples... creating their
stationery Hello World example as project C1, then running it and checking
the output in the Console View. Note that the StyledText casting code is
a little different. Your java examples were out of date, and I couldn't
figure out an exact mapping, but I take it you just wanted to have the
assert catch the problem if the StyledText cast was about to fail.

@Test
public void canCreateANewCProject() throws Exception {
SWTBotPerspective clangPerspective = bot.perspectiveByLabel("C/C++");
clangPerspective.activate();
bot.menu("File").menu("New").menu("Project...").click();

SWTBotShell shellProj = bot.shell("New Project");
shellProj.activate();
bot.waitUntil(shellIsActive("New Project"));
bot.tree().expandNode("C").select().click().select("C Project").click();
bot.button("Next >").click();

SWTBotShell shellC = bot.shell("C Project");
shellC.activate();

bot.textWithLabel("Project name:").setText("C1");
shellC.activate();
bot.tree().expandNode("Executable").select("Hello World ANSI C
Project").click();
shellC.activate();
bot.button("Finish").click();
bot.sleep(5000);
// FIXME: assert that the project is actually created, for later
}

@Test
public void canExecuteCApplication() throws Exception {
bot.viewByTitle("Project Explorer");
bot.tree().expandNode("C1").expandNode("Debug").select();
bot.menu("Run").menu("Run").click();
bot.sleep(5000);
bot.viewByTitle("Console").setFocus();
Widget consoleViewComposite = bot.getFocusedWidget();
assertThat (consoleViewComposite,instanceOf(StyledText.class));
StyledText console = (StyledText) consoleViewComposite;
SWTBotStyledText styledText = new SWTBotStyledText(console);

assertTextContains("Hello World", styledText);
}
Re: C tools test cases [message #459480 is a reply to message #457855] Sun, 02 August 2009 02:38 Go to previous messageGo to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
In that C test code there is a fixme that wants a check for the creation
of the executable. That can be with several lines of code below.

// Get the Workspace. Add this in beforeClass()
bot.menu("File").menu("Switch Workspace").menu("Other...").click();
workspacePath = bot.comboBoxWithLabel("Workspace:").getText();
bot.button("Cancel").click();

// Get the full path. Add this at the time to test for executable.
String fullpath = workspacePath + "/C1/Debug/C1.exe";
File executable = new File(fullpath);
assertTrue(executable.exists());

Maybe there's a simple fileExists matcher in all that imported code, but I
couldn't locate one. The Hamcrest site had a link to a site providing
File attribute tests:

http://www.time4tea.net/wiki/display/MAIN/Testing+Files+with +Hamcrest
Re: C tools test cases [message #459641 is a reply to message #459480] Sun, 02 August 2009 02:50 Go to previous messageGo to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
Maybe something like waitUntilFileExists(fullPath) would be more useful
than the assertTrue test that I added, since it would get rid of the
arbitrary wait for the build to complete. Is there already something like
that available?
Re: C tools test cases [message #459824 is a reply to message #457855] Sun, 02 August 2009 03:18 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan Padegaonkar
Messages: 873
Registered: July 2009
Senior Member
Looking at your email, I do not understand which of the steps is
failing, what is the expected behavior and what is actually happening.

--
Ketan
http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr

On 2/8/09 08:06, Jay Norwood wrote:
> Here are a couple of tests that I added for C with the mingw cdt tools
> installed. These are similar to your java examples... creating their
> stationery Hello World example as project C1, then running it and
> checking the output in the Console View. Note that the StyledText
> casting code is a little different. Your java examples were out of date,
> and I couldn't figure out an exact mapping, but I take it you just
> wanted to have the assert catch the problem if the StyledText cast was
> about to fail.
>
> @Test
> public void canCreateANewCProject() throws Exception {
> SWTBotPerspective clangPerspective = bot.perspectiveByLabel("C/C++");
> clangPerspective.activate();
> bot.menu("File").menu("New").menu("Project...").click();
>
> SWTBotShell shellProj = bot.shell("New Project");
> shellProj.activate();
> bot.waitUntil(shellIsActive("New Project"));
> bot.tree().expandNode("C").select().click().select("C Project").click();
> bot.button("Next >").click();
>
> SWTBotShell shellC = bot.shell("C Project");
> shellC.activate();
>
> bot.textWithLabel("Project name:").setText("C1");
> shellC.activate();
> bot.tree().expandNode("Executable").select("Hello World ANSI C
> Project").click();
> shellC.activate();
> bot.button("Finish").click();
> bot.sleep(5000);
> // FIXME: assert that the project is actually created, for later
> }
>
> @Test
> public void canExecuteCApplication() throws Exception {
> bot.viewByTitle("Project Explorer");
> bot.tree().expandNode("C1").expandNode("Debug").select();
> bot.menu("Run").menu("Run").click();
> bot.sleep(5000);
> bot.viewByTitle("Console").setFocus();
> Widget consoleViewComposite = bot.getFocusedWidget(); assertThat
> (consoleViewComposite,instanceOf(StyledText.class));
> StyledText console = (StyledText) consoleViewComposite;
> SWTBotStyledText styledText = new SWTBotStyledText(console);
>
> assertTextContains("Hello World", styledText);
> }
>
>
Re: C tools test cases [message #467838 is a reply to message #459824] Mon, 03 August 2009 02:15 Go to previous message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
All the examples I posted now work ok after adding that code that disables
the automatic switching of perspectives when going from Java to C
projects.

What I was seeing when the perspective changed is that bot.menu references
to the main toolbar menus would fail. I don't know why they would fail
other than the workbench bot was referencing something that lost focus
when the perspective changes.

That was my reason for previously asking about how the context is changing
in response to different statements. It seems to me that at least the
shell activations do change the context, as well as the setFocus on the
views.

I also recall it was necessary to move back out and activate the modal
preference settings shells before attempting to find the outer "OK"
button. I think the finders must only look at children from the context
of the last widget or composite that was selected. That's the feeling I
got while trying to figure out why some searches were failing.

You responded before that the context doesn't change, but there must be
some explanation when I can see the button in the shell, but the finder
doesn't locate it.
Previous Topic:eclipse perspective changes C to Java
Next Topic:context changes in SWTWorkbenchBot
Goto Forum:
  


Current Time: Fri Aug 01 12:03:27 EDT 2014

Powered by FUDForum. Page generated in 0.02034 seconds