| OLD | NEW |
| (Empty) |
| 1 // Copyright 2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #include <atlbase.h> | |
| 17 #include <atlcom.h> | |
| 18 #include "omaha/base/scoped_ptr_address.h" | |
| 19 #include "omaha/base/synchronized.h" | |
| 20 #include "omaha/base/utils.h" | |
| 21 #include "omaha/common/update3_utils.h" | |
| 22 #include "omaha/goopdate/model.h" | |
| 23 #include "omaha/testing/unit_test.h" | |
| 24 | |
| 25 namespace omaha { | |
| 26 | |
| 27 // TODO(omaha): there is a problem with this unit test. The model is built | |
| 28 // bottom up. This makes it impossible to set the references to parents. Will | |
| 29 // have to fix the code, eventually using Builder DP to create a bunch of | |
| 30 // models containing bundles, apps, and such. | |
| 31 | |
| 32 #if 0 | |
| 33 | |
| 34 const TCHAR* const kTestId = _T("{8260D23D-D23B-427F-AF1A-2CE36E6F073B}"); | |
| 35 | |
| 36 class IDummyUnknownImpl : public IUnknown { | |
| 37 public: | |
| 38 virtual ULONG STDMETHODCALLTYPE AddRef() { | |
| 39 return 1; | |
| 40 } | |
| 41 virtual ULONG STDMETHODCALLTYPE Release() { | |
| 42 return 1; | |
| 43 } | |
| 44 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void**) { | |
| 45 return E_NOTIMPL; | |
| 46 } | |
| 47 }; | |
| 48 | |
| 49 class AppVersionTest : public testing::Test { | |
| 50 protected: | |
| 51 LLock lock_; | |
| 52 }; | |
| 53 | |
| 54 TEST_F(AppVersionTest, TestReadOnly) { | |
| 55 IDummyUnknownImpl dummy_unknown; | |
| 56 scoped_ptr<AppVersion> app_version; | |
| 57 EXPECT_SUCCEEDED(AppVersion::Create(&lock_, | |
| 58 &dummy_unknown, | |
| 59 true, | |
| 60 address(app_version))); | |
| 61 | |
| 62 CComPtr<IAppDataReadOnly> version_data_ro; | |
| 63 EXPECT_SUCCEEDED(update3_utils::GetAppData(app_version.get(), | |
| 64 &version_data_ro)); | |
| 65 | |
| 66 CComPtr<IAppData> version_data_rw; | |
| 67 EXPECT_EQ(E_NOINTERFACE, | |
| 68 update3_utils::GetAppData(app_version.get(), &version_data_rw)); | |
| 69 | |
| 70 // Get the IDispatch interface, and verify that it is a read-only interface. | |
| 71 CComPtr<IDispatch> version_data_ro_dispatch; | |
| 72 EXPECT_SUCCEEDED( | |
| 73 version_data_ro.QueryInterface(&version_data_ro_dispatch)); | |
| 74 | |
| 75 CComVariant var; | |
| 76 EXPECT_SUCCEEDED(version_data_ro_dispatch.GetPropertyByName(_T("appGuid"), | |
| 77 &var)); | |
| 78 EXPECT_EQ(VT_BSTR, V_VT(&var)); | |
| 79 EXPECT_STREQ(GuidToString(GUID_NULL), V_BSTR(&var)); | |
| 80 | |
| 81 var = kTestId; | |
| 82 | |
| 83 // ITypeInfo::Invoke with a DISPATCH_PROPERTYPUT results in a | |
| 84 // DISP_E_BADPARAMCOUNT, and not in a DISP_E_MEMBERNOTFOUND, as I would have | |
| 85 // expected. | |
| 86 EXPECT_EQ(DISP_E_BADPARAMCOUNT, | |
| 87 version_data_ro_dispatch.PutPropertyByName(_T("appGuid"), &var)); | |
| 88 } | |
| 89 | |
| 90 TEST_F(AppVersionTest, TestReadWrite) { | |
| 91 IDummyUnknownImpl dummy_unknown; | |
| 92 scoped_ptr<AppVersion> app_version; | |
| 93 EXPECT_SUCCEEDED(AppVersion::Create(&lock_, | |
| 94 &dummy_unknown, | |
| 95 false, | |
| 96 address(app_version))); | |
| 97 | |
| 98 CComPtr<IAppDataReadOnly> version_data_ro; | |
| 99 EXPECT_SUCCEEDED(update3_utils::GetAppData(app_version.get(), | |
| 100 &version_data_ro)); | |
| 101 | |
| 102 CComPtr<IAppData> version_data_rw; | |
| 103 EXPECT_SUCCEEDED(update3_utils::GetAppData(app_version.get(), | |
| 104 &version_data_rw)); | |
| 105 | |
| 106 CComPtr<IUnknown> version_data_ro_unknown; | |
| 107 EXPECT_SUCCEEDED( | |
| 108 version_data_ro.QueryInterface(&version_data_ro_unknown)); | |
| 109 | |
| 110 CComPtr<IUnknown> version_data_rw_unknown; | |
| 111 EXPECT_SUCCEEDED( | |
| 112 version_data_rw.QueryInterface(&version_data_rw_unknown)); | |
| 113 | |
| 114 // COM identity rule. | |
| 115 EXPECT_TRUE(version_data_ro_unknown == version_data_rw_unknown); | |
| 116 | |
| 117 // Get the IDispatch interface, and verify that it is a read-write interface. | |
| 118 CComPtr<IDispatch> version_data_rw_dispatch; | |
| 119 EXPECT_SUCCEEDED( | |
| 120 version_data_rw.QueryInterface(&version_data_rw_dispatch)); | |
| 121 | |
| 122 CComVariant var; | |
| 123 EXPECT_SUCCEEDED(version_data_rw_dispatch.GetPropertyByName(_T("appGuid"), | |
| 124 &var)); | |
| 125 EXPECT_EQ(VT_BSTR, V_VT(&var)); | |
| 126 EXPECT_STREQ(GuidToString(GUID_NULL), V_BSTR(&var)); | |
| 127 | |
| 128 var = kTestId; | |
| 129 EXPECT_SUCCEEDED(version_data_rw_dispatch.PutPropertyByName(_T("appGuid"), | |
| 130 &var)); | |
| 131 | |
| 132 var.ClearToZero(); | |
| 133 EXPECT_SUCCEEDED(version_data_rw_dispatch.GetPropertyByName(_T("appGuid"), | |
| 134 &var)); | |
| 135 EXPECT_EQ(VT_BSTR, V_VT(&var)); | |
| 136 EXPECT_STREQ(kTestId, V_BSTR(&var)); | |
| 137 | |
| 138 // Verify that the read-only interface returns the same value for the appGuid. | |
| 139 CComBSTR app_id; | |
| 140 EXPECT_SUCCEEDED(version_data_ro->get_appId(&app_id)); | |
| 141 EXPECT_STREQ(kTestId, app_id); | |
| 142 } | |
| 143 | |
| 144 #endif | |
| 145 | |
| 146 } // namespace omaha | |
| OLD | NEW |