FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MicroOcpp/tests/RemoteStartTransaction.cpp at main · matth-x/MicroOcpp · GitHub
matth-x
/
MicroOcpp
Public
Notifications
You must be signed in to change notification settings
Fork
215
Star
540
Code
Issues
112
Pull requests
18
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
MicroOcpp
/
tests
/
RemoteStartTransaction.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
168 lines (142 loc) · 6.01 KB
Breadcrumbs
MicroOcpp
/
tests
/
RemoteStartTransaction.cpp
Copy path
File metadata and controls
168 lines (142 loc) · 6.01 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
matth-x/MicroOcpp
//
Copyright Matthias Akstaller 2019 - 2024
//
MIT License
#
include
<
MicroOcpp.h
>
#
include
<
MicroOcpp/Core/Connection.h
>
#
include
<
MicroOcpp/Core/Context.h
>
#
include
<
MicroOcpp/Core/Request.h
>
#
include
<
MicroOcpp/Core/Configuration.h
>
#
include
<
MicroOcpp/Core/OperationRegistry.h
>
#
include
<
MicroOcpp/Operations/CustomOperation.h
>
#
include
<
MicroOcpp/Model/Model.h
>
#
include
<
MicroOcpp/Model/ConnectorBase/Connector.h
>
#
include
<
MicroOcpp/Operations/RemoteStartTransaction.h
>
#
include
<
MicroOcpp/Debug.h
>
#
include
<
catch2/catch.hpp
>
#
include
"
./helpers/testHelper.h
"
using
namespace
MicroOcpp
;
TEST_CASE
(
"
RemoteStartTransaction
"
) {
printf
(
"
\n
Run %s
\n
"
,
"
RemoteStartTransaction
"
);
LoopbackConnection loopback;
mocpp_initialize
(loopback,
ChargerCredentials
(
"
test-runner1234
"
));
mocpp_set_timer
(custom_timer_cb);
loop
();
auto
context =
getOcppContext
();
auto
connector = context->
getModel
().
getConnector
(
1
);
SECTION
(
"
Basic remote start accepted
"
) {
//
Ensure connector idle
REQUIRE
(connector->
getStatus
() == ChargePointStatus_Available);
context->
initiateRequest
(
makeRequest
(
new
Ocpp16::CustomOperation
(
"
RemoteStartTransaction
"
,
[] () {
auto
doc =
makeJsonDoc
(
UNIT_MEM_TAG
,
JSON_OBJECT_SIZE
(
2
));
auto
payload = doc->
to
<JsonObject>();
payload[
"
idTag
"
] =
"
mIdTag
"
;
return
doc;},
[] (JsonObject) {}
)));
loop
();
REQUIRE
(connector->
getStatus
() == ChargePointStatus_Charging);
endTransaction
();
loop
();
REQUIRE
(connector->
getStatus
() == ChargePointStatus_Available);
}
SECTION
(
"
Same connectorId rejected when transaction active
"
) {
//
Start with connector 1 busy so remote start with connectorId=1 should not auto-assign
beginTransaction
(
"
anotherId
"
);
loop
();
REQUIRE
(connector->
getStatus
() == ChargePointStatus_Charging);
bool
checkProcessed =
false
;
context->
initiateRequest
(
makeRequest
(
new
Ocpp16::CustomOperation
(
"
RemoteStartTransaction
"
,
[] () {
auto
doc =
makeJsonDoc
(
UNIT_MEM_TAG
,
JSON_OBJECT_SIZE
(
3
));
auto
payload = doc->
to
<JsonObject>();
payload[
"
idTag
"
] =
"
mIdTag
"
;
payload[
"
connectorId
"
] =
1
;
//
the same connector already in use
return
doc;},
[&checkProcessed] (JsonObject response) {
checkProcessed =
true
;
REQUIRE
( !
strcmp
(response[
"
status
"
] |
"
_Undefined
"
,
"
Rejected
"
) );
}
)));
loop
();
//
Transaction should still be the original one only
REQUIRE
(checkProcessed);
REQUIRE
(connector->
getTransaction
());
REQUIRE
(
strcmp
(connector->
getTransaction
()->
getIdTag
(),
"
anotherId
"
) ==
0
);
REQUIRE
(connector->
getStatus
() == ChargePointStatus_Charging);
endTransaction
();
loop
();
REQUIRE
(connector->
getStatus
() == ChargePointStatus_Available);
}
SECTION
(
"
ConnectorId 0 rejected per spec
"
) {
//
RemoteStartTransaction response status is Rejected when connectorId == 0
REQUIRE
(connector->
getStatus
() == ChargePointStatus_Available);
bool
checkProcessed =
false
;
context->
initiateRequest
(
makeRequest
(
new
Ocpp16::CustomOperation
(
"
RemoteStartTransaction
"
,
[] () {
auto
doc =
makeJsonDoc
(
UNIT_MEM_TAG
,
JSON_OBJECT_SIZE
(
3
));
auto
payload = doc->
to
<JsonObject>();
payload[
"
idTag
"
] =
"
mIdTag
"
;
payload[
"
connectorId
"
] =
0
;
//
invalid per spec
return
doc;},
[&checkProcessed] (JsonObject response) {
checkProcessed =
true
;
REQUIRE
( !
strcmp
(response[
"
status
"
] |
"
_Undefined
"
,
"
Rejected
"
) );
}
)));
loop
();
REQUIRE
(checkProcessed);
REQUIRE
(connector->
getStatus
() == ChargePointStatus_Available);
}
SECTION
(
"
No free connector so rejected
"
) {
//
Occupy all connectors (limit defined by MO_NUMCONNECTORS)
for
(
unsigned
cId =
1
; cId < context->
getModel
().
getNumConnectors
(); cId++) {
auto
c = context->
getModel
().
getConnector
(cId);
if
(c) {
c->
beginTransaction_authorized
(
"
busyId
"
);
}
}
loop
();
bool
checkProcessed =
false
;
auto
freeFound =
false
;
for
(
unsigned
cId =
1
; cId < context->
getModel
().
getNumConnectors
(); cId++) {
auto
c = context->
getModel
().
getConnector
(cId);
if
(c && !c->
getTransaction
()) freeFound =
true
;
}
REQUIRE
(!freeFound);
//
ensure all are busy
context->
initiateRequest
(
makeRequest
(
new
Ocpp16::CustomOperation
(
"
RemoteStartTransaction
"
,
[] () {
auto
doc =
makeJsonDoc
(
UNIT_MEM_TAG
,
JSON_OBJECT_SIZE
(
2
));
auto
payload = doc->
to
<JsonObject>();
payload[
"
idTag
"
] =
"
mIdTag
"
;
return
doc;},
[&checkProcessed] (JsonObject response) {
checkProcessed =
true
;
REQUIRE
( !
strcmp
(response[
"
status
"
] |
"
_Undefined
"
,
"
Rejected
"
) );
}
)));
loop
();
REQUIRE
(checkProcessed);
//
No new transaction should be created; keep statuses
int
activeTx =
0
;
for
(
unsigned
cId =
1
; cId < context->
getModel
().
getNumConnectors
(); cId++) {
auto
c = context->
getModel
().
getConnector
(cId);
if
(c && c->
getTransaction
()) activeTx++;
}
REQUIRE
(activeTx == (
int
)context->
getModel
().
getNumConnectors
() -
1
);
//
all occupied
//
cleanup
for
(
unsigned
cId =
1
; cId < context->
getModel
().
getNumConnectors
(); cId++) {
auto
c = context->
getModel
().
getConnector
(cId);
if
(c && c->
getTransaction
()) {
c->
endTransaction
();
}
}
loop
();
REQUIRE
(connector->
getStatus
() == ChargePointStatus_Available);
}
mocpp_deinitialize
();
}
Back
|
FazBrowse Home
|
New Git URL