TS 67 CNDrefactoring
Refactoring Test Specification
Author: Dmitry Nikitin
Version: 1.2
Lastupdate: 08.08.2013
Introduction: Test specification for refactoring feature in CND Pack 7.4
Contents |
Test suite: Rename
Purpose: Verify Renaming file, class, macro, function, variable, typedef, namespace in CND Pack
Comment:
- Rename variable
- New Project > Sample > C/C++ > Welcome
- Open welcome.cc in editor (double click on Welcome > Source Files > welcome.cc on Project tab)
- Find line: int main(int argc, char**argv) { and click on argc
- Right-click on argc and select Refactor > Rename from popup menu (or Ctrl+R)
- Type new name for argc (e.g. arg_count) and press Enter
- EXPECTED RESULT: all occurrences of argc are renamed to arg_count.
- Rename class
- New Project > Sample > C/C++ > Quote
- Open memory.h in editor (double click on Quote > Header Files > memory.h on Project tab)
- Find line class Memory : public Module { and click on class name Memory
- Right-click on Memory and select Refactor > Rename from popup menu
'Rename' dialog box appears - Type new name for class and press Preview button
'Refactoring' view will appear. Memory is found in 11 occurrences, in memory.h (2), memory.cc (5) and in quote.cc (4) - Press Do Refactor button
all occurrences of Memory should be renamed - Build the project (Right-click on project node on Project tab and select Build from popup menu)
- EXPECTED RESULT: Build successful. It means that class Memory was renamed correctly.
- Rename macro
- New Project > Sample > C/C++ > Fractal
- Open fractal.cc in editor (double click on Fractal > Source Files > fractal.cc on Project tab)
- Find line #define MAXISIZE 500000 (line 43) and select MAXISIZE macro
- Press Ctrl+R or select Refactor > Rename from popup menu
Rename dialog box appears - Type new name for the macro and press Refactor button
- EXPECTED RESULT: all occurrences of MAXISIZE should be renamed
- Rename function
- New Project > Sample > C/C++ > Quote
- Open quote.cc in editor (double click on Quote > Source Files > quote.cc on Project tab)
- Find function readNumberOf (line 76)
- Click on on readNumberOf press Ctrl+R
Function name is highlighted in blue and a cursor appears in the end of function name - Type new name for the function and press Enter
- Save quote.cc (Ctrl+S)
- Build the project (Right-click on project node on Project tab and select Build from popup menu)
- EXPECTED RESULT: Build successful. It means that function readNumberOf was renamed correctly.
- Rename typedef
- New Project > C/C++ > C/C++ Application
- Open main.cc in editor (double click on Application > Source Files > main.cc on Project tab)
- Add the following code to source file
typedef int OldInt; OldInt MyInt(OldInt MyInt){ OldInt i = -1; return i*MyInt; }
- Select OldInt in the first line and press Ctrl+R or select Refactor > Rename from popup menu
'Rename' dialog box appears - Type new name for OldInt (e.g. NewInt) and press Refactor button
- EXPECTED RESULT: the code is transformed to
- Select OldInt in the first line and press Ctrl+R or select Refactor > Rename from popup menu
typedef int NewInt; NewInt MyInt(NewInt MyInt){ NewInt i = -1; return i*MyInt; }
- Rename namespace
- New Project > Sample > C/C++ > Welcome
- Open welcome.cc in editor (double click on Welcome > Source Files > welcome.cc on Project tab)
- Add the following code
namespace AA{ int var; namespace BB{ int var; } }
- Select
BB
and press Ctrl+R or Right-click and Refactor > Rename from popup menu - Type new name for
BB
namespace (e.g. {CC}) and press Refactor button
- EXPECTED RESULT: namespace should be renamed to
CC
and the piece of code should be:
- Select
{ namespace AA{ int var; namespace CC{ int var; } }
Test suite: Encapsulate field
Purpose:Verify if this part of refactoring functionality corresponds to design and works right
Comment:
- Encapsulate filed
- New Project > Sample > C/C++ > Quote
- Open customer.h in editor (double click on Quote > Header Files > customer.h on Project tab)
- Add private field 'age' int age; and click on age
- Right-click and select Refactor > Encapsulate Fields...
Encapsulate Fields dialog box appears - Verify that Create Getter and Create Setter methods are checked for 'age:int' field. Change getter/setter names if it's needed
- Press Preview button and after verifying the changes press Do Refactor button
- Build the project
- EXPECTED RESULT: The Project is built successful. It means that refactoring didn't break code.
Test suite: Change method parameters
Purpose:Verify if this part of refactoring functionality corresponds to design and works right
Comment:
- Adding new method parameters
- New Project > Sample > C/C++ > Quote
- Open system.cc in editor (double click on Quote > Source Files > system.cc on Project tab)
- Go to line 66 output << system.GetModule(i) << endl; and click on GetModule
- Right-click and select Refactor > Change Method Parameters ...
Change Method Parameters dialog box appears - Press Add button and type new parameter name, type and default value.
NB: Default value is parameter's value which will be passed to function - Press Preview button and after verifying the changes press Do Refactor button
- Build the project
- EXPECTED RESULT: The Project is built successful. It means that refactoring didn't break code.
- Removing method parameters
NB: You can remove only parameters which aren't used in method's body.- New Project > Sample > C/C++ > Quote
- Open system.cc in editor (double click on Quote > Source Files > system.cc on Project tab)
- Go to line 66 output << system.GetModule(i) << endl; and click on GetModule
- Add new parameter to GetModule method. See testcase Adding new method parameters above.
NB: new added parameter will be deleted in the next several steps
Now we are going to remove the parameter - Right-click and select Refactor > Change Method Parameters ...
Change Method Parameters dialog box appears - Select unused parameter and press Remove button
- Press Preview button and after verifying the changes press Do Refactor button
- Build the project
- EXPECTED RESULT: The Project is built successful. It means that refactoring didn't break code.