void deserialize(const T& expected, const v8& data, int expectedLeft = 0, SerializationContext* ctx = nullptr) { SerializationContext sctx; SCOPED_TRACE(::testing::PrintToString(expected.serialize(sctx)) + " = " + ::testing::PrintToString(data)); std::unique_ptr<SerializationContext> dummy; if (!ctx) { dummy.reset(new SerializationContext()); ctx = dummy.get(); } auto it = data.begin(); try { T i = T::deserialize(it, data.end(), *ctx); ASSERT_EQ(expected, i); } catch(std::exception& e) { FAIL() << "Deserialization threw exception:\n" << e.what() ; } ASSERT_EQ(expectedLeft, data.end() - it) << "Expected " << expectedLeft << " bytes left, got " << (data.end() - it) << " bytes left"; }
static void consistsOf(std::vector<v8> parts, const v8& data) { auto it = data.begin(); while (it != data.end()) { if (parts.empty()) { FAIL() << "Unexpected elements left in data: " << testing::PrintToString(v8(it, data.end())) << std::endl; return; } std::vector<v8>::iterator found = findElement(it, parts); if (found == parts.end()) { ADD_FAILURE() << "None of the following values could be found at position " << std::distance(data.begin(), it) << " of data:\n" << testing::PrintToString(v8(it, data.end())) << "\n"; for (auto part : parts) std::cerr << testing::PrintToString(part) << "\n"; return; } it += found->size(); parts.erase(found); } ASSERT_TRUE(parts.empty()); }
void IMessageDlg::_init(const v8::FunctionCallbackInfo<v8::Value>& args) { Isolate* isolate = args.GetIsolate(); IMessageDlg* obj = new IMessageDlg(); // Create messagedlg obj->hwnd = IupMessageDlg(); if (args.Length()>=1 && args[0]->IsNumber()) { int ty = args[0]->Int32Value(); switch(ty) { case 1: IupSetStrAttribute(obj->hwnd,"BUTTONS", "OKCANCEL"); IupSetStrAttribute(obj->hwnd,"DIALOGTYPE", "QUESTION"); break; case 2: IupSetStrAttribute(obj->hwnd,"BUTTONS", "YESNO"); IupSetStrAttribute(obj->hwnd,"DIALOGTYPE", "QUESTION"); break; default: IupSetStrAttribute(obj->hwnd,"BUTTONS", "OK"); IupSetStrAttribute(obj->hwnd,"DIALOGTYPE", "INFORMATION"); break; } } if (args.Length()>=2 && args[1]->IsString()) { Local<String> tt = Local<String>::Cast(args[1]); String::Utf8Value str(tt); IupSetStrAttribute(obj->hwnd,"TITLE", *str); } if (args.Length()>=3 && args[2]->IsString()) { Local<String> tt = Local<String>::Cast(args[2]); String::Utf8Value str(tt); IupSetStrAttribute(obj->hwnd,"VALUE", *str); } obj->Wrap(args.This()); args.GetReturnValue().Set(Undefined(isolate)); }
void IMessageDlg::_popup(const v8::FunctionCallbackInfo<v8::Value>& args) { Isolate* isolate = args.GetIsolate(); IMessageDlg* imd = ObjectWrap::Unwrap<IMessageDlg>(args.Holder()); if (imd != NULL) { if (imd->hwnd != NULL) { IupPopup(imd->hwnd, IUP_CURRENT, IUP_CURRENT); } } args.GetReturnValue().Set(Undefined(isolate)); }
void IMessageDlg::_destroy(const v8::FunctionCallbackInfo<v8::Value>& args) { Isolate* isolate = args.GetIsolate(); IMessageDlg* imd = ObjectWrap::Unwrap<IMessageDlg>(args.Holder()); if (imd != NULL) { if (imd->hwnd != NULL) { IupDestroy(imd->hwnd); imd->hwnd = NULL; } } args.GetReturnValue().Set(Undefined(isolate)); }
static void deserializesTo(const T& expected, v8 data, int left = 0) { SCOPED_TRACE(::testing::PrintToString(expected) + " = " + ::testing::PrintToString(data)); auto it = data.cbegin(); try { Deserializer d; T i = d.deserialize(it, data.cend()).as<T>(); ASSERT_EQ(expected, i); T j = *d.deserialize(data).asPtr<T>(); ASSERT_EQ(expected, j); DeserializationContext ctx; T k = Deserializer::deserialize(data, ctx).as<T>(); ASSERT_EQ(expected, k); } catch(std::exception& e) { FAIL() << "Deserialization threw exception:\n" << e.what() ; } ASSERT_EQ(left, data.cend() - it) << "Expected " << left << " bytes left, got " << (data.cend() - it) << " bytes left"; }
static inline void isEqual(const std::vector<u8>& expected, const v8& serialized) { ASSERT_EQ(expected, serialized) << "Expected length " << expected.size() << ", got " << serialized.size(); }