-
Notifications
You must be signed in to change notification settings - Fork 10
/
UTCClass.prw
1757 lines (1426 loc) · 46.4 KB
/
UTCClass.prw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include 'totvs.ch'
#Include 'Protheus.ch'
#INCLUDE 'FWMVCDEF.CH'
/*/{Protheus.doc} UTCClass
(long_description)
@author andrews.egas
@since 06/04/2018
@version ${version}
@example
(examples)
@see (links_or_references)
/*/
CLASS UTCClass FROM FwModelEvent
DATA _cProgram as char
DATA _lAuto as logical
DATA cNegField as char
DATA cNegVal as char
DATA Def0 as Array
DATA VERSION as Array
DATA RELEASE as Array
DATA SEEK as Array
DATA COUNTRY as Array
DATA OPERATION as Array
DATA BRANCH as Array
DATA STEP as Array
DATA DEF_SX1 as Array
DATA DATA_SX1 as Array
DATA DEF_SX6 as Array
DATA DATA_SX6 as Array
DATA DEF_VARS as Array
DATA DATA_VARS as Array
DATA DEF_MASTER as Array
DATA DATA_MASTER as Array
DATA DEF_ITEMS as Array
DATA DATA_ITEMS as Array
DATA CKP_QUERY as Array
DATA CKP_DEF as Array
DATA CKP_RELEASE as Array
DATA CKP_RESULT as Array
DATA CKP_ASSERT as Array
DATA lNegativeTest as logical
DATA lTemplate as logical
METHOD New() constructor
METHOD SetProgram()
METHOD SetAuto()
//Padroes do Observer
METHOD DeActivate()
METHOD Activate()
METHOD GridLinePreVld()
METHOD FieldPreVld()
METHOD SetOperation()
METHOD FieldPosVld()
METHOD GridLinePosVld()
//--------
METHOD UpdCheckPoint()
METHOD UpdDetail()
METHOD UpdMaster()
METHOD getRelatVal()
METHOD GenerateCsv()
METHOD SetNegative()
METHOD UpdNegative()
METHOD AddSeek()
METHOD GeneratePrw()
METHOD GenerateKanoah()
METHOD FieldTypeStr()
METHOD GenerateTIR()
METHOD GenerateRotAuto()
METHOD UtcFinalGenerate()
END CLASS
/*/{Protheus.doc} new
constructor
@author andrews.egas
@since 05/04/2018
@version 1.0
/*/
METHOD new() class UTCClASS
::_cProgram := ""
::_lAuto := .F.
//Def0
::Def0 := Array(3)
::Def0[1] := "Def0"
::Def0[2] := "Key"
::Def0[3] := "Def 1"
//Version
::VERSION := Array(3)
::VERSION[1] :="VERSION"
//Release
::RELEASE := Array(3)
::RELEASE[1] :="RELEASE"
//Country
::COUNTRY := Array(3)
::COUNTRY[1] :="COUNTRY"
::COUNTRY[3] :=IIf(!Empty(cPaisLoc),cPaisLoc,"")
//Operation
::OPERATION := Array(3)
::OPERATION[1] :="OPERATION"
//Branch
::BRANCH := Array(3)
::BRANCH[1] :="BRANCH"
::BRANCH[3] :=xFilial()
//Step
::STEP := Array(3)
::STEP[1] :="STEP"
//Defines SX1
::DEF_SX1 := Array(3)
::DATA_SX1 := Array(3)
::DEF_SX1[1] :="DEFINITION"
::DEF_SX1[2] :="SX1"
::DATA_SX1[1] :="DATA"
::DATA_SX1[2] :="SX1"
//Defines SX6
::DEF_SX6 := Array(3)
::DATA_SX6 := Array(3)
::DEF_SX6[1] :="DEFINITION"
::DEF_SX6[2] :="SX6"
::DATA_SX6[1] :="DATA"
::DATA_SX6[2] :="SX6"
//Defines Variables
::DEF_VARS := Array(3)
::DATA_VARS := Array(3)
::DEF_VARS[1] :="DEFINITION"
::DEF_VARS[2] :="VARS"
::DEF_VARS[3] := "dDatabase"
::DATA_VARS[1] :="DATA"
::DATA_VARS[2] :="VARS"
::DATA_VARS[3] := "'" + dtoc(dDatabase) + "'"
Return
/*/{Protheus.doc} setProgram
Set the program - routine
@author Andrews.Egas
@since 06/04/2018
@version 1.0
/*/
Method SetProgram(cProgram) Class UTCClass
::_cProgram := cProgram
Return
/*/{Protheus.doc} setProgram
Set if is automatic from .INI
@author Andrews.Egas
@since 17/07/2018
@version 1.0
/*/
Method SetAuto(lAuto) Class UTCClass
::_lAuto := lAuto
Return
/*/{Protheus.doc} Activate
Model Activate to start variables
@author Andrews.Egas
@since 06/04/2018
@version 1.0
/*/
Method Activate(oModel,lCopy) Class UTCClass
::cNegField := ""
::cNegVal := ""
::lNegativeTest := .F.
If !Empty(::DEF_MASTER)
//clear arrays for a new test case
aSize(::DEF_MASTER, 0)
aSize(::DATA_MASTER, 0)
aSize(::SEEK, 0)
aSize(::DEF_ITEMS, 0)
aSize(::DATA_ITEMS, 0)
aSize(::CKP_QUERY, 0)
aSize(::CKP_DEF, 0)
aSize(::CKP_RELEASE, 0)
aSize(::CKP_RESULT, 0)
aSize(::CKP_ASSERT, 0)
EndIf
//Defines Master - Header
::DEF_MASTER := Array(1,3)
::DATA_MASTER := Array(1,3)
//Defines Details Grid
::DEF_ITEMS := Array(1,3)
::DATA_ITEMS := Array(1,3)
::SEEK := Array(4)
//Defines Check Points
::CKP_QUERY := Array(1,3)
::CKP_DEF := Array(1,2)
::CKP_RELEASE := Array(1,2)
::CKP_RESULT := Array(1,2)
::CKP_ASSERT := Array(1,3)
::SetOperation(oModel:getOperation()) //Set Operation
If ::OPERATION[2] == "4" .OR. ::OPERATION[2] == "5" //edit or delete
::AddSeek(oModel)
EndIf
Return .T.
/*/{Protheus.doc} DeActivate
Model pos validation method to generate CSV
@author Andrews.Egas
@since 06/04/2018
@version 1.0
/*/
Method DeActivate(oModel) Class UTCClass
Local oSubModel as object
Local cModelId as character
Local aCheck as array
If Empty(::CKP_QUERY[1][2]) .And. ::lNegativeTest
//if is negative test we neet to set just one checkpoint
cModelId := oModel:GetDependency()[1][2]
oSubModel := oModel:GetModel(cModelId)
::UpdNegative(oSubModel,cModelId)
::UtcFinalGenerate(oModel) //Generate Files
ElseIf !Empty(::CKP_QUERY[1][2]) .Or. ::OPERATION[2] == "5" // if is empty, it is just closing the routine or delete operatio
::UtcFinalGenerate(oModel) //Generate Files
EndIf
Return .T.
/*/{Protheus.doc} FieldPreVld
pre validation to update Master fields that were changed
Model pos validation method.
@author Andrews.Egas
@since 06/04/2018
@version 1.0
/*/
Method FieldPreVld(oSubModel, cModelID, cAction, cId, xValue) Class UTCClass
Local cValue as character
If cAction == "SETVALUE" .And. xValue <> NIL .And. ::DEF_MASTER <> NIL
If ValType(xValue) == "C"
cValue := xValue
ElseIf ValType(xValue) == "D"
cValue := allTrim(dtoC(xValue))
ElseIf ValType(xValue) == "L" // adicionado validacao para variavel logica
cValue := allTrim(cValToChar(xValue))
Else
cValue := allTrim(str(xValue))
EndIf
//If oSubModel:CanSetValue(cId)
If ::lNegativeTest
::cNegField := cId
::cNegVal := cValue
::UpdNegative(oSubModel,cModelId,0)
EndIf
::UpdMaster(cModelID,cId,cValue)
//EndIf
conout(cId + " FIELD PRE")
EndIf
Return .T.
/*/{Protheus.doc} GridLinePreVld
pre validation to update CSV
Grid Model pos validation method.
@author Andrews.Egas
@since 06/04/2018
@version 1.0
/*/
Method GridLinePreVld(oSubModel, cModelId, nLine, cAction, cId, xValue, xCurrentValue) Class UTCClass
Local nPosModel as numeric
Local nPosField as numeric
Local cValue as character
If cAction == "SETVALUE" .And. xValue <> NIL .And. ::DEF_MASTER <> NIL
If ValType(xValue) == "C"
cValue := xValue
ElseIf ValType(xValue) == "D"
cValue := allTrim(dtoC(xValue))
ElseIf ValType(xValue) == "L" // adicionado validacao para variavel logica
cValue := allTrim(cValToChar(xValue))
Else
cValue := allTrim(str(xValue))
EndIf
//If oSubModel:CanSetValue(cId)
::UpdDetail(cModelID,nLine,cId,cValue)
If ::lNegativeTest
::cNegField := cId
::cNegVal := cValue
::UpdNegative(oSubModel,cModelId,nLine)
EndIf
//EndIf
conout(cId + " GRID PRE")
EndIf
Return .T.
//-------------------------------------------------------------------
/*/{Protheus.doc} FieldPosVld
Field Pos validation
@author andrews.egas
@since 12/04/2018
@version 1.0
/*/
//-------------------------------------------------------------------
Method FieldPosVld(oSubModel, cModelID) Class UTCClass
local n as numeric
Local ctable as character
Local cQuery as character
Local aKey as Array
Local aValues as Array
Local xValue
Local nNext as numeric
Local aFunc as array
aFunc := array(2)
cQuery := ""
ctable := oSubModel:GetStruct():GetTable()[1]
//check if already exist the same table (MVC MODELO 1) the same table master and grid
If !Empty(ctable ) .And. Ascan(::CKP_DEF,{|x| allTrim(ctable) $ Alltrim(x[2])}) == 0
aKey := STRTOKARR((ctable)->(IndexKey(1)),'+')
If at("_FILIAL",aKey[1] ) > 0
aDel(aKey,1)
aSize(aKey,Len(aKey)-1)
EndIf
aValues:= array(len(aKey))
For n:=1 to Len(aKey)
//validation for fields with function in the KEY example DTOS(FIELD)
If oSubModel:GetIdField(aKey[n]) > 0
aValues[n] := oSubModel:GetValue(aKey[n])
Else
//delete functions in the key, example DTOS(FIELD)
If (at("(",akey[2]) > 0)
aFunc[1] := substr(akey[n],1,at("(",akey[n])) //save first part of function
aKey[n] := substr(aKey[n],at("(",akey[n])+1)
nNext := Iif(at(",",akey[n])>0,at(",",akey[n]),at(")",akey[n])) //take next point
aFunc[2] := substr(akey[n],nNext,len(akey[n])) //save seconf part of function
aKey[n] := substr(aKey[n],1,nNext-1)
xValue := oSubModel:GetValue(aKey[n])
If ValType(xValue) == "D"
aValues[n] := DTOS(xValue)
ElseIf ValType(xValue) == "N"
aValues[n] := alltrim(STR(xValue))
aValues[n] := &(afunc[1]+aValues[n]+aFunc[2]) //exec function with parameters that was in the key
Else
aValues[n] := xValue
EndIf
EndIf
EndIf
cQuery += AllTrim(aKey[n]) + " = '" + aValues[n]+ "'" //return values for query
If n < Len(aKey)
cQuery += " AND "
EndIf
If ::OPERATION[2] <> "4" // update doesn't need set key
//update KEY fields, maybe they were not changed manually
::UpdMaster(cModelID,aKey[n],aValues[n])
EndIf
Next
::UpdCheckPoint(ctable,cQuery,aKey,aValues,"")
EndIf
conout(cModelId +" FIELD POS OK")
Return .T.
//-------------------------------------------------------------------
/*/{Protheus.doc} GridLinePosVld
Grid Pos valid
@author andrews.egas
@since 12/04/2018
@version 1.0
/*/
//-------------------------------------------------------------------
Method GridLinePosVld(oSubModel, cModelID, nLine) Class UTCClass
local n as numeric
Local ctable as character
Local cQuery as character
Local aKey as Array
Local aValues as Array
Local aRelation as Array
Local nIsInRel as numeric
local aFunc as Array
Local nNext as numeric
Local oModelOw as Object
Local xValue
If ::DEF_MASTER <> NIL //If it runs before it open the view will be .F.
aFunc := array(2)
cQuery := ""
ctable := oSubModel:oFormModelStruct:getTable()[1]
aRelation:= oSubModel:getrelation()[1]
aKey := STRTOKARR((ctable)->(IndexKey(1)),'+')
If at("_FILIAL",aKey[1] ) > 0
aDel(aKey,1)
aSize(aKey,Len(aKey)-1)
EndIf
aValues:= array(len(aKey))
For n:=1 to Len(aKey)
//if the key field is in relation it was not update manually, lets update
nIsInRel := Ascan(aRelation,{|x| Alltrim(x[1]) == allTrim(aKey[n])})
if nIsInRel > 0
aValues[n] := ::getRelatVal(oSubModel,cModelId,aRelation[nIsInRel]) //Take the resault of relation
Else
If (at("(",akey[n]) > 0)
//delete functions in the key, example DTOS(FIELD)
aFunc[1] := substr(akey[n],1,at("(",akey[n])) //save first part of function
aKey[n] := substr(aKey[n],at("(",akey[n])+1)
nNext := Iif(at(",",akey[n])>0,at(",",akey[n]),at(")",akey[n])) //take next point
aFunc[2] := substr(akey[n],nNext,len(akey[n])) //save seconf part of function
aKey[n] := substr(aKey[n],1,nNext-1)
EndIf
If oSubModel:GetModel():GetIdField(aKey[n],@oModelOw) > 0
xValue := oModelOw:GetValue(aKey[n],nLine)
Else
Loop
EndIf
If ValType(xValue) == "D"
aValues[n] := DTOS(xValue) //no parameters
ElseIf ValType(xValue) == "N"
aValues[n] := alltrim(STR(xValue))
aValues[n] := &(afunc[1]+aValues[n]+aFunc[2]) //exec function with parameters that was in the key
Else
aValues[n] := xValue
EndIf
EndIf
cQuery += AllTrim(aKey[n]) + " = '" + aValues[n] + "'" //return values for query
If n < Len(aKey)
cQuery += " AND "
EndIf
If ::OPERATION[2] <> "4" // update doesnt need to set key
//update KEY fields, maybe they were not changed manually
::UpdDetail(cModelID,nLine,aKey[n],aValues[n])
EndIf
Next
If !Empty(aValues) .And. !Empty(aValues[1])
::UpdCheckPoint(ctable,cQuery,aKey,aValues,AllTrim(str(nLine)))
EndIf
EndIf
conout(" GRID POS ")
Return .T.
//-------------------------------------------------------------------
/*/{Protheus.doc} SetOperation
set the operation
@param nOperation, numeric, Operation
@author andrews.egas
@since 12/04/2018
@version 1.0
/*/
//-------------------------------------------------------------------
METHOD SetOperation( nOperation ) Class UTCClass
::OPERATION[2] := AllTrim(str(nOperation))
Return
//-------------------------------------------------------------------
/*/{Protheus.doc} UpdMaster
Update Master definitions or create
@param cModelID, character, Model Id
@param cId, character, Field Id
@param cValue, character, Value
@author andrews.egas
@since 13/04/2018
@version 1.0
/*/
//-------------------------------------------------------------------
METHOD UpdMaster(cModelID,cId,cValue) Class UTCClASS
Local nPosModel as numeric
Local nPosField as numeric
//First time to fill Master data
If Empty(::DEF_MASTER[1][2])
::DEF_MASTER[1][1] :="DEFINITION"
::DATA_MASTER[1][1] :="DATA"
::DEF_MASTER[1][2] :=cModelID
::DATA_MASTER[1][2] :=cModelID
::DEF_MASTER[1][3] :=cId
::DATA_MASTER[1][3] :=cValue
Else
nPosModel := Ascan(::DEF_MASTER,{|x| Alltrim(x[2]) == allTrim(cModelID)}) //seek structure id of model
If nPosModel > 0
//master already exist
nPosField := Ascan(::DEF_MASTER[nPosModel],allTrim(cId) ) //seek field inside this model
If nPosField > 0
//field already exist, just update value
::DEF_MASTER[nPosModel][nPosField] :=cId
::DATA_MASTER[nPosModel][nPosField] :=cValue
Else
//add new field in the structure
aAdd(::DEF_MASTER[nPosModel],cId)
aAdd(::DATA_MASTER[nPosModel],cValue)
EndIf
Else
//add new Master
aAdd(::DEF_MASTER,{"DEFINITION",cModelID,cId})
aAdd(::DATA_MASTER,{"DATA",cModelID,cValue})
EndIf
EndIf
Return
//-------------------------------------------------------------------
/*/{Protheus.doc} UpdDetail
Update Details definitions or create
@param cModelID, character, Detail Id
@param nLine, numeric, Grid Line
@param cId, character, Field Id
@param cValue, character, Value
@author andrews.egas
@since 13/04/2018
@version 1.0
/*/
//-------------------------------------------------------------------
METHOD UpdDetail(cModelID,nLine,cId,cValue) Class UTCClASS
Local nPosModel as numeric
Local nPosField as numeric
Local cLine as character
cLine := AllTrim(str(nLine))
//First time to fill Master data
If Empty(::DEF_ITEMS[1][2])
::DEF_ITEMS[1][1] :="DEFINITION"
::DATA_ITEMS[1][1] :="DATA_ITEMS"
::DEF_ITEMS[1][2] :=cModelID + cLine //Here is the line control
::DATA_ITEMS[1][2] :=cModelID
::DEF_ITEMS[1][3] :=cId
::DATA_ITEMS[1][3] :=cValue
Else
nPosModel := Ascan(::DEF_ITEMS,{|x| Alltrim(x[2]) == allTrim(cModelID + cLine)}) //seek structure id of model + line
If nPosModel > 0
//Details ID already exist
nPosField := Ascan(::DEF_ITEMS[nPosModel],allTrim(cId) ) //seek field inside this model
If nPosField > 0
//field already exist, just update value
::DEF_ITEMS[nPosModel][nPosField] :=cId
::DATA_ITEMS[nPosModel][nPosField] :=cValue
Else
//add new field in the structure
aAdd(::DEF_ITEMS[nPosModel],cId)
aAdd(::DATA_ITEMS[nPosModel],cValue)
EndIf
Else
//add new Details ID
aAdd(::DEF_ITEMS,{"DEFINITION",cModelID + cLine,cId})
aAdd(::DATA_ITEMS,{"DATA_ITEMS",cModelID,cValue})
EndIf
EndIf
Return
//-------------------------------------------------------------------
/*/{Protheus.doc} UpdCheckPoint
Update Details definitions or create
@param ctable, character, Table
@param cQuery, numeric , SQL Query
@param aFields, array , fields to check
@param aValues, array , Values of aFields
@author andrews.egas
@since 13/04/2018
@version 1.0
/*/
//-------------------------------------------------------------------
METHOD UpdCheckPoint(ctable,cQuery,aFields,aValues,cLine,lNegativeTest) Class UTCClASS
Local nPosCKP as numeric
Local n as numeric
Local nA as numeric
Default lNegativeTest := .F.
If lNegativeTest
//Clean array, negative test must be just one checkpoint
for nA := 2 to Len(::CKP_QUERY)
aDel(::CKP_QUERY,nA)
aDel(::CKP_DEF,nA)
aDel(::CKP_RESULT,nA)
aDel(::CKP_ASSERT,nA)
Next
aSize(::CKP_QUERY,1)
aSize(::CKP_DEF,1)
aSize(::CKP_DEF[1],2)
aSize(::CKP_RESULT,1)
aSize(::CKP_RESULT[1],2)
aSize(::CKP_ASSERT,1)
::CKP_QUERY[1][2] := "" //force to entry in the <First time to fill check point data>
EndIf
//First time to fill CheckPoint data
If Empty(::CKP_QUERY[1][2])
::CKP_QUERY[1][1] :="CHECKPOINT_QUERY"
::CKP_DEF[1][1] :="CHECKPOINT_DEFINITION"
::CKP_RESULT[1][1] :="CHECKPOINT_RESULT"
::CKP_ASSERT[1][1] :="CHECKPOINT_ASSERT"
::CKP_QUERY[1][2] := ctable
::CKP_DEF[1][2] := ctable + cLine //Include line if is grid
::CKP_RESULT[1][2] := ctable
::CKP_ASSERT[1][2] :=""
::CKP_QUERY[1][3] :=cQuery
for n := 1 to Len(aFields)
aAdd(::CKP_DEF[1] ,aFields[n])
aAdd(::CKP_RESULT[1],aValues[n])
Next
If lNegativeTest .Or. ::OPERATION[2] == "5" // delete
::CKP_ASSERT[1][3] :="False"
Else
::CKP_ASSERT[1][3] :="True"
EndIf
Else
nPosCKP := Ascan(::CKP_DEF,{|x| Alltrim(x[2]) == allTrim(ctable + cLine)}) //seek structure id of model + line
If nPosCKP > 0
//CheckPoint already exist
::CKP_QUERY[nPosCKP][3] := cQuery
for n := 1 to Len(aFields)
::CKP_DEF[nPosCKP][(n+2)] := aFields[n]
::CKP_RESULT[nPosCKP][(n+2)] := aValues[n]
Next
::CKP_ASSERT[nPosCKP][3] :="True"
Else
//there is no checkPont for this table + line
aAdd(::CKP_QUERY,{"CHECKPOINT_QUERY" ,ctable ,cQuery})
aAdd(::CKP_DEF ,{"CHECKPOINT_DEFINITION",ctable + cLine})
aAdd(::CKP_RESULT,{"CHECKPOINT_RESULT" ,ctable})
aAdd(::CKP_ASSERT,{"CHECKPOINT_ASSERT" ,"" ,"True"})
for n := 1 to Len(aFields)
aAdd(::CKP_DEF[Len(::CKP_DEF)] , aFields[n])
aAdd(::CKP_RESULT[Len(::CKP_RESULT)], aValues[n])
Next
EndIf
EndIf
Return
//-------------------------------------------------------------------
/*/{Protheus.doc} UpdCheckPoint
Get value from relation between tables
@param oSubModel object , Model structure
@param cModelId, character , Id do model
@param aRelation, array , relation to return
@author andrews.egas
@since 13/04/2018
@version 1.0
/*/
//-------------------------------------------------------------------
METHOD getRelatVal(oSubModel,cModelId,aRelation) Class UTCClASS
Local cIdOwner as character
Local oModelOw as object
Local xReturn
If oSubModel:GetModel():GetIdField(aRelation[2],@oModelOw) > 0
xReturn := oModelOw:GetValue(aRelation[2]) //Take the value in oModelOw (Model with the field)
Else
xReturn := &(aRelation[2]) //advpl expression
EndIf
Return xReturn
//-------------------------------------------------------------------
/*/{Protheus.doc} GenerateCsv
generates the CSV file
@author andrews.egas
@since 13/04/2018
@version 1.0
/*/
//-------------------------------------------------------------------
METHOD GenerateCsv(cName) Class UTCClASS
Local lRet as logical
Local nBFile as numeric
Local cFileName as Character
Local cContFile as Character
Local n as numeric
Local nItem as numeric
Local cName as character
lRet := .T.
If FindFunction(::_cProgram + cPaisLoc)
//generate Test Case with RUS name
Else
//Generate Test Case normal
EndIf
cFileName := ::_cProgram
// CSV Creation
If !File("\UTCTOOL\" +cFileName + "_" + cName + ".CSV") //check if the file already exist, and create next one
nBFile := FCREATE("\UTCTOOL\" + cFileName + "_" + cName + ".CSV")
Else
nBFile := FCREATE("\UTCTOOL\" + cFileName + "_" + cName + "_002"+".CSV")//changehere
EndIf
If nBFile == -1 //check if was possible to crate the file
MsgStop('Erro ao criar destino. Ferror = '+str(ferror(),4),'Erro')
lRet := .F.
Else
cContFile :="" //start to write the file
For n := 1 to Len(::Def0)
cContFile += IIF(::Def0[n] == NIL,"",::Def0[n]) + ","
Next
cContFile += CRLF
For n := 1 to Len(::VERSION)
cContFile += IIF(::VERSION[n] == NIL,"",::VERSION[n]) + ","
Next
cContFile += CRLF
For n := 1 to Len(::RELEASE)
cContFile += IIF(::RELEASE[n] == NIL,"",::RELEASE[n]) + ","
Next
cContFile += CRLF
For n := 1 to Len(::COUNTRY)
cContFile += IIF(::COUNTRY[n] == NIL,"",::COUNTRY[n]) + ","
Next
cContFile += CRLF
For n := 1 to Len(::BRANCH)
cContFile += IIF(::BRANCH[n] == NIL,"",::BRANCH[n]) + ","
Next
cContFile += CRLF
For n := 1 to Len(::STEP)
cContFile += IIF(::STEP[n] == NIL,"",::STEP[n]) + ","
Next
cContFile += CRLF
For n := 1 to Len(::OPERATION)
cContFile += IIF(::OPERATION[n] == NIL,"",::OPERATION[n]) + ","
Next
cContFile += CRLF
For n := 1 to Len(::DEF_VARS)
cContFile += IIF(::DEF_VARS[n] == NIL,"",::DEF_VARS[n]) + ","
Next
cContFile += CRLF
For n := 1 to Len(::DATA_VARS)
cContFile += IIF(::DATA_VARS[n] == NIL,"",::DATA_VARS[n]) + ","
Next
cContFile += CRLF
For n := 1 to Len(::DEF_SX1)
cContFile += IIF(::DEF_SX1[n] == NIL,"",::DEF_SX1[n]) + ","
Next
cContFile += CRLF
For n := 1 to Len(::DATA_SX1)
cContFile += IIF(::DATA_SX1[n] == NIL,"",::DATA_SX1[n]) + ","
Next
cContFile += CRLF
For n := 1 to Len(::DEF_SX6)
cContFile += IIF(::DEF_SX6[n] == NIL,"",::DEF_SX6[n]) + ","
Next
cContFile += CRLF
For n := 1 to Len(::DATA_SX6)
cContFile += IIF(::DATA_SX6[n] == NIL,"",::DATA_SX6[n]) + ","
Next
If !Empty(::SEEK[1]) //check if there is SEEK in this test case (Update or delete)
cContFile += CRLF
For n := 1 to Len(::SEEK)
cContFile += ::SEEK[n] + ","
Next
EndIf
If !Empty(::DEF_MASTER[1][2]) //If we don't have Master it is DELETE
For n := 1 to Len(::DEF_MASTER)
cContFile += CRLF //master Head
//master
For nItem := 1 to Len(::DEF_MASTER[n])
cContFile += ::DEF_MASTER[n][nItem] + ","
Next
cContFile += CRLF
// data master
For nItem := 1 to Len(::DATA_MASTER[n])
If nItem > 2
cContFile +='"' + ::DATA_MASTER[n][nItem] + '",'
Else
cContFile += ::DATA_MASTER[n][nItem] + ","
EndIf
Next
Next
EndIf
If !Empty(::DEF_ITEMS[1][2]) //check if we have details in this test
For n := 1 to Len(::DEF_ITEMS)
cContFile += CRLF //start Details
For nItem := 1 to Len(::DEF_ITEMS[n])
If nItem == 2 //If is the second, the line is here, use data_items
cContFile += ::DATA_ITEMS[n][nItem] + ","
Else
cContFile += ::DEF_ITEMS[n][nItem] + ","
EndIf
Next
cContFile += CRLF
// data details
For nItem := 1 to Len(::DATA_ITEMS[n])
If nItem > 2
cContFile += '"' + ::DATA_ITEMS[n][nItem] + '",'
Else
cContFile += ::DATA_ITEMS[n][nItem] + ","
EndIf
Next
Next
EndIf
For n := 1 to Len(::CKP_QUERY)
cContFile += CRLF //Check Points
//Query
For nItem := 1 to Len(::CKP_QUERY[n])
cContFile += IIF(::CKP_QUERY[n][nItem] == NIL,"",::CKP_QUERY[n][nItem]) + ","
Next
cContFile += CRLF
// Definitions of fields to check
For nItem := 1 to Len(::CKP_DEF[n])
If nItem == 2 //If is the second, the line is here, use ckp_result
cContFile += IIF(::CKP_RESULT[n][nItem] == NIL,"",::CKP_RESULT[n][nItem]) + ","
Else
cContFile += IIF(::CKP_DEF[n][nItem] == NIL,"",::CKP_DEF[n][nItem]) + ","
EndIf
Next
cContFile += CRLF
// Result of fields
For nItem := 1 to Len(::CKP_RESULT[n])
If nItem > 2
cContFile += '"' + ::CKP_RESULT[n][nItem] + '",'
Else
cContFile += ::CKP_RESULT[n][nItem] + ","
EndIf
Next
cContFile += CRLF
// Assert
For nItem := 1 to Len(::CKP_ASSERT[n])
cContFile += IIF(::CKP_ASSERT[n][nItem] == NIL,"",::CKP_ASSERT[n][nItem]) + ","
Next
Next
conout("criado")
FWRITE(nBFile,cContFile)
FCLOSE(nBFile)
MsgInfo(cFileName + "_" + cName + ".CSV successfully generated", 'Test Case')
EndIf
Return
//-------------------------------------------------------------------
/*/{Protheus.doc} SetNegative
Negative Test
@author andrews.egas
@since 12/04/2018
@version 1.0
/*/
//-------------------------------------------------------------------
Method SetNegative() Class UTCClass
MsgInfo('Your next change (FIELD OR CONFIRMATION) must be the last, ','Negative Test')
::lNegativeTest := .T.
Return
//-------------------------------------------------------------------
/*/{Protheus.doc} UpdNegative
Creation JUST negative check point and delete others
@param oSubModel, object, SubModel
@param cModelId, character , Model id
@param nLine, numeric , line if grid
@author andrews.egas
@since 13/04/2018
@version 1.0
/*/
//-------------------------------------------------------------------
METHOD UpdNegative(oSubModel,cModelId,nLine) Class UTCClASS
Local cQuery as character
Local ctable as character
Local aKey as Array
Local aValues as Array
Local aRelation as Array
Local nIsInRel as numeric
Local cLine as character
Local n as numeric
Default nLine := 0
cLine := ""
cQuery := ""
ctable := oSubModel:GetStruct():GetTable()[1]
aKey := STRTOKARR((ctable)->(IndexKey(1)),'+')
If at("_FILIAL",aKey[1] ) > 0
aDel(aKey,1)
aSize(aKey,Len(aKey)-1)
EndIf
aValues:= array(len(aKey))
If !Empty(nLine)
cLine := AllTrim(str(nLine))