1
+ package org .cpputest .plugin .SWTBotTest ;
2
+
3
+ import static org .junit .Assert .*;
4
+
5
+ import org .eclipse .core .runtime .CoreException ;
6
+ import org .eclipse .swtbot .eclipse .finder .SWTWorkbenchBot ;
7
+ import org .eclipse .swtbot .eclipse .finder .widgets .SWTBotEclipseEditor ;
8
+ import org .eclipse .swtbot .swt .finder .junit .SWTBotJunit4ClassRunner ;
9
+ import org .eclipse .swtbot .swt .finder .utils .SWTBotPreferences ;
10
+ import org .eclipse .swtbot .swt .finder .widgets .SWTBotShell ;
11
+ import org .junit .After ;
12
+ import org .junit .AfterClass ;
13
+ import org .junit .Before ;
14
+ import org .junit .BeforeClass ;
15
+ import org .junit .Ignore ;
16
+ import org .junit .Test ;
17
+ import org .junit .runner .RunWith ;
18
+
19
+ @ RunWith (SWTBotJunit4ClassRunner .class )
20
+ public class IncompleteSelectionTest extends CppProjectTestBase {
21
+
22
+ private static final String GENERAL_PROJECT_FOR_TESTING = "GeneralProjectForTesting" ;
23
+
24
+ @ Before
25
+ public void setupProjectAndClearClipboard () throws CoreException {
26
+ createCppProject (GENERAL_PROJECT_FOR_TESTING );
27
+ clearClipboard ();
28
+ }
29
+ @ After
30
+ public void cleanProject () throws CoreException {
31
+ deleteProject (GENERAL_PROJECT_FOR_TESTING );
32
+ }
33
+ @ BeforeClass
34
+ static public void increaseTimeOut () {
35
+ SWTBotPreferences .TIMEOUT = 20000 ;
36
+ }
37
+ @ AfterClass
38
+ static public void waitForAWhile (){
39
+ SWTWorkbenchBot bot = new SWTWorkbenchBot ();
40
+ bot .sleep (2000 );
41
+ }
42
+ @ Test
43
+ public void onlySelectedFunctionsShouldBeUsedWhenSelectCompleteFunctionSignature () throws CoreException {
44
+ SWTBotEclipseEditor editor = openAnEditorWith3Functions ();
45
+ editor .selectLine (1 );
46
+ fireTheCopyEmptyStubToClipboardMenuItem ();
47
+ assertEquals ("void fun2(){}\n " , getClipboardContent ());
48
+ }
49
+ @ Test
50
+ public void theFunctionAfterTheCurserShouldBeUsedWhenPutCurserAtTheBeginingOfTheSignature () throws CoreException {
51
+ SWTBotEclipseEditor editor = openAnEditorWith3Functions ();
52
+ editor .selectRange (1 , 0 , 0 );
53
+ fireTheCopyEmptyStubToClipboardMenuItem ();
54
+ assertEquals ("void fun2(){}\n " , getClipboardContent ());
55
+ }
56
+ @ Test
57
+ public void theFunctionOnTheCurserShouldBeUsedWhenPutCurserInTheMiddleOfTheSignature () throws CoreException {
58
+ SWTBotEclipseEditor editor = openAnEditorWith3Functions ();
59
+ editor .selectRange (1 , 7 , 0 );
60
+ fireTheCopyEmptyStubToClipboardMenuItem ();
61
+ assertEquals ("void fun2(){}\n " , getClipboardContent ());
62
+ }
63
+ @ Test
64
+ public void onlyTheCompleteFunctionsInTheSelectionShouldBeUsedWhenSelectMultipleSignature () throws CoreException {
65
+ SWTBotEclipseEditor editor = openAnEditorWith3Functions ();
66
+ editor .selectRange (0 , 7 //start from the middle of fun1
67
+ , 39 // end at the middle of fun4
68
+ );
69
+ fireTheCopyEmptyStubToClipboardMenuItem ();
70
+ assertEquals ("void fun2(){}\n void fun3(){}\n " , getClipboardContent ());
71
+ }
72
+
73
+ protected SWTBotEclipseEditor openAnEditorWith3Functions ()
74
+ throws CoreException {
75
+ SWTBotEclipseEditor editor = createNewCppFile (GENERAL_PROJECT_FOR_TESTING , "example.h" ,
76
+ "void fun1();" +System .getProperty ("line.separator" )+
77
+ "void fun2();" +System .getProperty ("line.separator" )+
78
+ "void fun3();" +System .getProperty ("line.separator" )+
79
+ "void fun4();" );
80
+ return editor ;
81
+ }
82
+ }
0 commit comments