@@ -1086,7 +1086,27 @@ namespace tut
1086
1086
return false ;
1087
1087
}
1088
1088
1089
- std::list<LLSD> mHistory ;
1089
+ template <typename CALLABLE>
1090
+ void checkHistory (CALLABLE&& code)
1091
+ {
1092
+ try
1093
+ {
1094
+ // we expect this lambda to contain tut::ensure() calls
1095
+ std::forward<CALLABLE>(code)(mHistory );
1096
+ }
1097
+ catch (const failure&)
1098
+ {
1099
+ LL_INFOS () << " event history:" << LL_ENDL;
1100
+ for (const LLSD& item : mHistory )
1101
+ {
1102
+ LL_INFOS () << item << LL_ENDL;
1103
+ }
1104
+ throw ;
1105
+ }
1106
+ }
1107
+
1108
+ using Listory = std::list<LLSD>;
1109
+ Listory mHistory ;
1090
1110
LLTempBoundListener mConnection ;
1091
1111
};
1092
1112
@@ -1137,23 +1157,26 @@ namespace tut
1137
1157
// finish out the run
1138
1158
waitfor (*py.mPy );
1139
1159
// now verify history
1140
- std::list<LLSD>::const_iterator li (listener.mHistory .begin ()),
1141
- lend (listener.mHistory .end ());
1142
- ensure (" no events" , li != lend);
1143
- ensure_equals (" history[0]" , (*li)[" data" ].asString (), " abc" );
1144
- ensure_equals (" history[0] len" , (*li)[" len" ].asInteger (), 3 );
1145
- ++li;
1146
- ensure (" only 1 event" , li != lend);
1147
- ensure_equals (" history[1]" , (*li)[" data" ].asString (), " abcdef" );
1148
- ensure_equals (" history[0] len" , (*li)[" len" ].asInteger (), 6 );
1149
- ++li;
1150
- ensure (" only 2 events" , li != lend);
1151
- ensure_equals (" history[2]" , (*li)[" data" ].asString (), " abcdefghi" EOL);
1152
- ensure_equals (" history[0] len" , (*li)[" len" ].asInteger (), 9 + sizeof (EOL) - 1 );
1153
- ++li;
1154
- // We DO NOT expect a whole new event for the second line because we
1155
- // disconnected.
1156
- ensure (" more than 3 events" , li == lend);
1160
+ listener.checkHistory (
1161
+ [](const EventListener::Listory& history)
1162
+ {
1163
+ auto li (history.begin ()), lend (history.end ());
1164
+ ensure (" no events" , li != lend);
1165
+ ensure_equals (" history[0]" , (*li)[" data" ].asString (), " abc" );
1166
+ ensure_equals (" history[0] len" , (*li)[" len" ].asInteger (), 3 );
1167
+ ++li;
1168
+ ensure (" only 1 event" , li != lend);
1169
+ ensure_equals (" history[1]" , (*li)[" data" ].asString (), " abcdef" );
1170
+ ensure_equals (" history[0] len" , (*li)[" len" ].asInteger (), 6 );
1171
+ ++li;
1172
+ ensure (" only 2 events" , li != lend);
1173
+ ensure_equals (" history[2]" , (*li)[" data" ].asString (), " abcdefghi" EOL);
1174
+ ensure_equals (" history[0] len" , (*li)[" len" ].asInteger (), 9 + sizeof (EOL) - 1 );
1175
+ ++li;
1176
+ // We DO NOT expect a whole new event for the second line because we
1177
+ // disconnected.
1178
+ ensure (" more than 3 events" , li == lend);
1179
+ });
1157
1180
}
1158
1181
1159
1182
template <> template <>
@@ -1173,14 +1196,17 @@ namespace tut
1173
1196
// (or any other intervening layer) does crazy buffering. What we want
1174
1197
// to ensure is that there was exactly ONE event with "eof" true, and
1175
1198
// that it was the LAST event.
1176
- std::list<LLSD>::const_reverse_iterator rli (listener.mHistory .rbegin ()),
1177
- rlend (listener.mHistory .rend ());
1178
- ensure (" no events" , rli != rlend);
1179
- ensure (" last event not \" eof\" " , (*rli)[" eof" ].asBoolean ());
1180
- while (++rli != rlend)
1181
- {
1182
- ensure (" \" eof\" event not last" , ! (*rli)[" eof" ].asBoolean ());
1183
- }
1199
+ listener.checkHistory (
1200
+ [](const EventListener::Listory& history)
1201
+ {
1202
+ auto rli (history.rbegin ()), rlend (history.rend ());
1203
+ ensure (" no events" , rli != rlend);
1204
+ ensure (" last event not \" eof\" " , (*rli)[" eof" ].asBoolean ());
1205
+ while (++rli != rlend)
1206
+ {
1207
+ ensure (" \" eof\" event not last" , ! (*rli)[" eof" ].asBoolean ());
1208
+ }
1209
+ });
1184
1210
}
1185
1211
1186
1212
template <> template <>
@@ -1203,13 +1229,17 @@ namespace tut
1203
1229
ensure_equals (" getLimit() after setlimit(10)" , childout.getLimit (), 10 );
1204
1230
// okay, pump I/O to pick up output from child
1205
1231
waitfor (*py.mPy );
1206
- ensure (" no events" , ! listener.mHistory .empty ());
1207
- // For all we know, that data could have arrived in several different
1208
- // bursts... probably not, but anyway, only check the last one.
1209
- ensure_equals (" event[\" len\" ]" ,
1210
- listener.mHistory .back ()[" len" ].asInteger (), abc.length ());
1211
- ensure_equals (" length of setLimit(10) data" ,
1212
- listener.mHistory .back ()[" data" ].asString ().length (), 10 );
1232
+ listener.checkHistory (
1233
+ [abc](const EventListener::Listory& history)
1234
+ {
1235
+ ensure (" no events" , ! history.empty ());
1236
+ // For all we know, that data could have arrived in several different
1237
+ // bursts... probably not, but anyway, only check the last one.
1238
+ ensure_equals (" event[\" len\" ]" ,
1239
+ history.back ()[" len" ].asInteger (), abc.length ());
1240
+ ensure_equals (" length of setLimit(10) data" ,
1241
+ history.back ()[" data" ].asString ().length (), 10 );
1242
+ });
1213
1243
}
1214
1244
1215
1245
template <> template <>
@@ -1276,18 +1306,22 @@ namespace tut
1276
1306
params.postend = pumpname;
1277
1307
LLProcessPtr child = LLProcess::create (params);
1278
1308
ensure (" shouldn't have launched" , ! child);
1279
- ensure_equals (" number of postend events" , listener.mHistory .size (), 1 );
1280
- LLSD postend (listener.mHistory .front ());
1281
- ensure (" has id" , ! postend.has (" id" ));
1282
- ensure_equals (" desc" , postend[" desc" ].asString (), std::string (params.desc ));
1283
- ensure_equals (" state" , postend[" state" ].asInteger (), LLProcess::UNSTARTED);
1284
- ensure (" has data" , ! postend.has (" data" ));
1285
- std::string error (postend[" string" ]);
1286
- // All we get from canned parameter validation is a bool, so the
1287
- // "validation failed" message we ourselves generate can't mention
1288
- // "executable" by name. Just check that it's nonempty.
1289
- // ensure_contains("error", error, "executable");
1290
- ensure (" string" , ! error.empty ());
1309
+ listener.checkHistory (
1310
+ [¶ms](const EventListener::Listory& history)
1311
+ {
1312
+ ensure_equals (" number of postend events" , history.size (), 1 );
1313
+ LLSD postend (history.front ());
1314
+ ensure (" has id" , ! postend.has (" id" ));
1315
+ ensure_equals (" desc" , postend[" desc" ].asString (), std::string (params.desc ));
1316
+ ensure_equals (" state" , postend[" state" ].asInteger (), LLProcess::UNSTARTED);
1317
+ ensure (" has data" , ! postend.has (" data" ));
1318
+ std::string error (postend[" string" ]);
1319
+ // All we get from canned parameter validation is a bool, so the
1320
+ // "validation failed" message we ourselves generate can't mention
1321
+ // "executable" by name. Just check that it's nonempty.
1322
+ // ensure_contains("error", error, "executable");
1323
+ ensure (" string" , ! error.empty ());
1324
+ });
1291
1325
}
1292
1326
1293
1327
template <> template <>
@@ -1309,16 +1343,20 @@ namespace tut
1309
1343
{
1310
1344
yield ();
1311
1345
}
1312
- ensure (" no postend event" , i < timeout);
1313
- ensure_equals (" number of postend events" , listener.mHistory .size (), 1 );
1314
- LLSD postend (listener.mHistory .front ());
1315
- ensure_equals (" id" , postend[" id" ].asInteger (), childid);
1316
- ensure (" desc empty" , ! postend[" desc" ].asString ().empty ());
1317
- ensure_equals (" state" , postend[" state" ].asInteger (), LLProcess::EXITED);
1318
- ensure_equals (" data" , postend[" data" ].asInteger (), 35 );
1319
- std::string str (postend[" string" ]);
1320
- ensure_contains (" string" , str, " exited" );
1321
- ensure_contains (" string" , str, " 35" );
1346
+ listener.checkHistory (
1347
+ [i, timeout, childid](const EventListener::Listory& history)
1348
+ {
1349
+ ensure (" no postend event" , i < timeout);
1350
+ ensure_equals (" number of postend events" , history.size (), 1 );
1351
+ LLSD postend (history.front ());
1352
+ ensure_equals (" id" , postend[" id" ].asInteger (), childid);
1353
+ ensure (" desc empty" , ! postend[" desc" ].asString ().empty ());
1354
+ ensure_equals (" state" , postend[" state" ].asInteger (), LLProcess::EXITED);
1355
+ ensure_equals (" data" , postend[" data" ].asInteger (), 35 );
1356
+ std::string str (postend[" string" ]);
1357
+ ensure_contains (" string" , str, " exited" );
1358
+ ensure_contains (" string" , str, " 35" );
1359
+ });
1322
1360
}
1323
1361
1324
1362
struct PostendListener
0 commit comments