Skip to content

Commit

Permalink
Merge pull request #10 from msabbott/8_TempTable
Browse files Browse the repository at this point in the history
Allow temp-tables to be defined inside of test doubles. Fixes #8
  • Loading branch information
msabbott committed Apr 21, 2015
2 parents 6cbee52 + c683c90 commit 02662ff
Show file tree
Hide file tree
Showing 25 changed files with 2,237 additions and 6 deletions.
79 changes: 79 additions & 0 deletions OEMock/BaseDouble.cls
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,84 @@ CLASS OEMock.BaseDouble:

AddProcedureParameter(parm).
END METHOD.

METHOD PUBLIC VOID AddTempTable(INPUT ttHandle AS HANDLE):

DEFINE VARIABLE ttObject AS OEMock.Reflection.TempTable NO-UNDO.
DEFINE VARIABLE ttField AS OEMock.Reflection.TempTableField NO-UNDO.
DEFINE VARIABLE ttIndex AS OEMock.Reflection.TempTableIndex NO-UNDO.
DEFINE VARIABLE ttIdxField AS OEMock.Reflection.TempTableIndexField NO-UNDO.
DEFINE VARIABLE ttBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE fieldLoop AS INTEGER NO-UNDO.
DEFINE VARIABLE bufField AS HANDLE NO-UNDO.
DEFINE VARIABLE indexLoop AS INTEGER NO-UNDO.
DEFINE VARIABLE indexData AS CHARACTER NO-UNDO.
DEFINE VARIABLE idxField AS INTEGER NO-UNDO.

IF NOT VALID-HANDLE(ttHandle) THEN RETURN.

/* Set properties on object, and fetch buffer handle */
ASSIGN ttObject = NEW OEMock.Reflection.TempTable(INPUT ttHandle:NAME)
ttObject:NamespacePrefix = ttHandle:NAMESPACE-PREFIX
ttObject:NamespaceURI = ttHandle:NAMESPACE-URI
ttObject:NoUndo = NOT(ttHandle:UNDO)
ttBuffer = ttHandle:DEFAULT-BUFFER-HANDLE.

/* Loop through buffer information to create field list */
DO fieldLoop = 1 TO ttBuffer:NUM-FIELDS:

ASSIGN bufField = ttBuffer:BUFFER-FIELD(fieldLoop)
ttField = NEW OEMock.Reflection.TempTableField(INPUT bufField:NAME, INPUT bufField:DATA-TYPE).

/* Set temp-table field properties */
ASSIGN ttField:Extent = bufField:EXTENT
ttField:Initial = bufField:INITIAL
ttField:SerializeHidden = bufField:SERIALIZE-HIDDEN
ttField:SerializeName = bufField:SERIALIZE-NAME
ttField:XMLDataType = bufField:XML-DATA-TYPE
ttField:XMLNodeType = bufField:XML-NODE-TYPE
ttField:XMLNodeName = bufField:XML-NODE-NAME.

ttObject:Fields:AddTempTableField(ttField).
END.

/* Loop through index information */
ASSIGN indexLoop = 1
indexData = ttBuffer:INDEX-INFORMATION(indexLoop).

indexLoop:
DO WHILE(indexData NE ?):

/* If the name of the index is 'default' and there are only 5 entries in the list, then
* this is the default index, and there were no explicit indexes added to the temp-table
*/
IF ENTRY(1, indexData) = "default" AND NUM-ENTRIES(indexData) = 5 THEN LEAVE indexLoop.

ASSIGN ttIndex = NEW OEMock.Reflection.TempTableIndex(ENTRY(1, indexData))
ttIndex:Unique = (ENTRY(2,indexData) = "1")
ttIndex:Primary = (ENTRY(3,indexData) = "1")
ttIndex:WordIndex = (ENTRY(4,indexData) = "1").

/* Remaining data is field list, following by 0 for ascending, 1 for descending */
ASSIGN idxField = 5.
indexFieldLoop:
DO WHILE(idxField <= NUM-ENTRIES(indexData)):

ASSIGN ttIdxField = NEW OEMock.Reflection.TempTableIndexField(ENTRY(idxField, indexData))
ttIdxField:Descending = (ENTRY(idxField + 1, indexData) = "1")
idxField = idxField + 2.

ttIndex:Fields:AddTempTableIndexField(ttIdxField).
END.

ttObject:Indexes:AddTempTableIndex(ttIndex).

ASSIGN indexLoop = indexLoop + 1
indexData = ttBuffer:INDEX-INFORMATION(indexLoop).
END.

THIS-OBJECT:File:TempTables:AddTempTable(INPUT ttObject).

END METHOD.

END CLASS.
7 changes: 7 additions & 0 deletions OEMock/Reflection/BaseFile.cls
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

USING Progress.Lang.*.
USING OEMock.Util.StringList.
USING OEMock.Reflection.TempTableList.

ROUTINE-LEVEL ON ERROR UNDO, THROW.

Expand All @@ -20,16 +21,22 @@ CLASS OEMock.Reflection.BaseFile:

DEFINE PUBLIC PROPERTY UsingList AS OEMock.Util.StringList NO-UNDO
GET.
PROTECTED SET.

DEFINE PUBLIC PROPERTY TempTables AS OEMock.Reflection.TempTableList NO-UNDO
GET.
PROTECTED SET.

CONSTRUCTOR BaseFile(INPUT fname AS CHARACTER):
SUPER().
ASSIGN FileName = fname.
UsingList = NEW StringList().
TempTables = NEW TempTableList().
END CONSTRUCTOR.

DESTRUCTOR BaseFile():
IF VALID-OBJECT(UsingList) THEN DELETE OBJECT UsingList.
IF VALID-OBJECT(TempTables) THEN DELETE OBJECT TempTables.
END DESTRUCTOR.

METHOD PUBLIC LONGCHAR Generate():
Expand Down
20 changes: 20 additions & 0 deletions OEMock/Reflection/ClassFile.cls
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,38 @@ CLASS OEMock.Reflection.ClassFile INHERITS BaseFile:
+ "&1&6"
+ "&1&7"
+ "&1&8"
+ "&1&9"
+ "&1END CLASS.&1",
CHR(10) + CHR(13),
IF INDEX(TypeName, " ") > 0 THEN '"' + TypeName + '"' ELSE TypeName,
(IF InheritsFrom NE ? AND TRIM(InheritsFrom) NE "" THEN "INHERITS " + TRIM(InheritsFrom) + " " ELSE ""),
GenerateInterfaces(),
GenerateTempTables(),
GenerateDataSets(),
GenerateConstructors(),
GenerateMethods(),
Generators:Generate()).
RETURN res.
END METHOD.

METHOD PROTECTED LONGCHAR GenerateTempTables():
DEFINE VARIABLE res AS LONGCHAR NO-UNDO.
DEFINE VARIABLE ttab AS OEMock.Reflection.TempTable NO-UNDO.

/* Loop through datasets */
ttab = TempTables:MoveFirst().
DO WHILE VALID-OBJECT(ttab):
ASSIGN res = res + ttab:Generate()
+ CHR(10) + CHR(13)
ttab = TempTables:MoveNext().
END.

/* Sanity check output */
IF res = ? THEN res = "".

RETURN res.
END METHOD.

METHOD PROTECTED LONGCHAR GenerateDataSets():
DEFINE VARIABLE res AS LONGCHAR NO-UNDO.
DEFINE VARIABLE dset AS OEMock.Reflection.DataSet NO-UNDO.
Expand Down
23 changes: 21 additions & 2 deletions OEMock/Reflection/ProcedureFile.cls
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CLASS OEMock.Reflection.ProcedureFile INHERITS BaseFile:

DEFINE PUBLIC PROPERTY Procedures AS OEMock.Reflection.MethodList NO-UNDO
GET.
PROTECTED SET.
PROTECTED SET.

CONSTRUCTOR PUBLIC ProcedureFile(INPUT fname AS CHARACTER):
SUPER(INPUT fname).
Expand All @@ -56,9 +56,10 @@ CLASS OEMock.Reflection.ProcedureFile INHERITS BaseFile:
METHOD OVERRIDE PUBLIC LONGCHAR Generate():
DEFINE VARIABLE res AS LONGCHAR NO-UNDO.

ASSIGN res = SUBSTITUTE("&1&2&1&3&1&4&1&5&1&6&1&7&1&8",
ASSIGN res = SUBSTITUTE("&1&2&1&3&1&4&1&5&1&6&1&7&1&8&1&9",
CHR(10) + CHR(13),
GenerateUsing(),
GenerateTempTables(),
GenerateDataSets(),
GenerateParameters(),
GenerateFunctionForwards(),
Expand All @@ -69,6 +70,24 @@ CLASS OEMock.Reflection.ProcedureFile INHERITS BaseFile:
RETURN res.
END METHOD.

METHOD PROTECTED LONGCHAR GenerateTempTables():
DEFINE VARIABLE res AS LONGCHAR NO-UNDO.
DEFINE VARIABLE ttab AS OEMock.Reflection.TempTable NO-UNDO.

/* Loop through datasets */
ttab = TempTables:MoveFirst().
DO WHILE VALID-OBJECT(ttab):
ASSIGN res = res + ttab:Generate()
+ CHR(10) + CHR(13)
ttab = TempTables:MoveNext().
END.

/* Sanity check output */
IF res = ? THEN res = "".

RETURN res.
END METHOD.

METHOD PROTECTED LONGCHAR GenerateDataSets():
DEFINE VARIABLE res AS LONGCHAR NO-UNDO.
DEFINE VARIABLE dset AS OEMock.Reflection.DataSet NO-UNDO.
Expand Down
95 changes: 95 additions & 0 deletions OEMock/Reflection/TempTable.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*------------------------------------------------------------------------
File : TempTable
Purpose : Represents a Temp-Table in code.
----------------------------------------------------------------------*/

USING Progress.Lang.*.
USING OEMock.Reflection.TempTableField.
USING OEMock.Reflection.TempTableFieldList.
USING OEMock.Reflection.TempTableIndex.
USING OEMock.Reflection.TempTableIndexList.

ROUTINE-LEVEL ON ERROR UNDO, THROW.

CLASS OEMock.Reflection.TempTable:

DEFINE PUBLIC PROPERTY Fields AS OEMock.Reflection.TempTableFieldList NO-UNDO
GET.
PROTECTED SET.

DEFINE PUBLIC PROPERTY Indexes AS OEMock.Reflection.TempTableIndexList NO-UNDO
GET.
PROTECTED SET.

DEFINE PUBLIC PROPERTY Name AS CHARACTER NO-UNDO
GET.
PROTECTED SET.

DEFINE PUBLIC PROPERTY NamespacePrefix AS CHARACTER NO-UNDO
GET.
SET.

DEFINE PUBLIC PROPERTY NamespaceURI AS CHARACTER NO-UNDO
GET.
SET.

DEFINE PUBLIC PROPERTY NoUndo AS LOGICAL INITIAL TRUE NO-UNDO
GET.
SET.

DEFINE PUBLIC PROPERTY Static AS LOGICAL INITIAL FALSE NO-UNDO
GET.
SET.

CONSTRUCTOR PUBLIC TempTable(INPUT nam AS CHARACTER):
SUPER().

ASSIGN THIS-OBJECT:Fields = NEW TempTableFieldList()
THIS-OBJECT:Indexes = NEW TempTableIndexList()
Name = nam
NamespacePrefix = ""
NamespaceURI = ""
NoUndo = TRUE
THIS-OBJECT:Static = FALSE.
END CONSTRUCTOR.

DESTRUCTOR PUBLIC TempTable():
IF VALID-OBJECT(THIS-OBJECT:Fields) THEN DELETE OBJECT THIS-OBJECT:Fields.
IF VALID-OBJECT(THIS-OBJECT:Indexes) THEN DELETE OBJECT THIS-OBJECT:Indexes.
END DESTRUCTOR.

METHOD PUBLIC LONGCHAR Generate():

DEFINE VARIABLE res AS LONGCHAR NO-UNDO.
DEFINE VARIABLE fld AS TempTableField NO-UNDO.
DEFINE VARIABLE idx AS TempTableIndex NO-UNDO.

res = SUBSTITUTE("DEFINE &2TEMP-TABLE &3&4&5&6&1",
CHR(10),
(IF THIS-OBJECT:Static THEN "STATIC " ELSE ""),
NAME,
(IF NoUndo THEN " NO-UNDO " ELSE ""),
(IF NamespacePrefix NE ? AND NamespacePrefix NE "" THEN "NAMESPACE-PREFIX ~"" + NamespacePrefix + "~" " ELSE ""),
(IF NamespaceURI NE ? AND NamespaceURI NE "" THEN "NAMESPACE-URI ~"" + NamespaceURI + "~" " ELSE "")).

/* Build field list */
fld = THIS-OBJECT:Fields:MoveFirst().
DO WHILE(VALID-OBJECT(fld)):
res = res + " " + fld:Generate().
fld = THIS-OBJECT:Fields:MoveNext().
END.

/* Build index list */
idx = THIS-OBJECT:Indexes:MoveFirst().
DO WHILE(VALID-OBJECT(idx)):
res = res + " " + idx:Generate().
idx = THIS-OBJECT:Indexes:MoveNext().
END.

/* Trim contents and add ending fullstop */
ASSIGN res = TRIM(TRIM(res),".") + ".".

RETURN res.
END METHOD.

END CLASS.
Loading

0 comments on commit 02662ff

Please sign in to comment.