@@ -77,6 +77,167 @@ namespace TestMatching
7777 Assert::IsTrue (app.matchSimpleWildCard (url, pattern));
7878 }
7979 };
80+
81+ TEST_CLASS (MatchRegularExpression)
82+ {
83+ public:
84+ TEST_METHOD (ExactMatch)
85+ {
86+ DefaultConfig config;
87+ BrowserSelector app (config);
88+ wstring url (L" https://www.example.com" );
89+ wstring pattern (L" https://www\\ .example\\ .com" );
90+ Assert::IsTrue (app.matchRegex (url, pattern));
91+ }
92+
93+ TEST_METHOD (WildCard)
94+ {
95+ DefaultConfig config;
96+ BrowserSelector app (config);
97+ wstring url (L" https://www.example.com" );
98+ wstring pattern (L" .*example.*" );
99+ Assert::IsTrue (app.matchRegex (url, pattern));
100+ }
101+
102+ TEST_METHOD (UnmatchToPartial)
103+ {
104+ DefaultConfig config;
105+ BrowserSelector app (config);
106+ wstring url (L" https://www.example.com" );
107+ wstring pattern (L" example" );
108+ Assert::IsFalse (app.matchRegex (url, pattern));
109+ }
110+
111+ TEST_METHOD (Unmatch)
112+ {
113+ DefaultConfig config;
114+ BrowserSelector app (config);
115+ wstring url (L" https://www2.example.com" );
116+ wstring pattern (L" https://www\\ .example\\ .com" );
117+ Assert::IsFalse (app.matchRegex (url, pattern));
118+ }
119+
120+ TEST_METHOD (UNCPath)
121+ {
122+ DefaultConfig config;
123+ BrowserSelector app (config);
124+ wstring url (L" \\\\ shared\\ folder" );
125+ wstring pattern (L" \\\\\\\\ shared\\\\ folder" );
126+ Assert::IsTrue (app.matchRegex (url, pattern));
127+ }
128+ };
129+
130+ TEST_CLASS (GetBrowserNameToOpenURL)
131+ {
132+ public:
133+ TEST_METHOD (WildCardMatchFirstUrlPattern1)
134+ {
135+ DefaultConfig config;
136+ config.m_urlPatterns = {
137+ { L" not-match" , L" ie" },
138+ { L" http*://*.example.com/*" , L" firefox" },
139+ { L" http*://*.example.com/*" , L" ie" },
140+ };
141+ BrowserSelector app (config);
142+ wstring url (L" https://www.example.com/" );
143+ Assert::AreEqual (L" firefox" , app.GetBrowserNameToOpenURL (url).c_str ());
144+ }
145+
146+ TEST_METHOD (WildCardMatchFirstUrlPattern2)
147+ {
148+ DefaultConfig config;
149+ config.m_urlPatterns = {
150+ { L" not-match" , L" ie" },
151+ { L" http*://*.example.com/*" , L" ie" },
152+ { L" http*://*.example.com/*" , L" firefox" },
153+ };
154+ BrowserSelector app (config);
155+ wstring url (L" https://www.example.com/" );
156+ Assert::AreEqual (L" ie" , app.GetBrowserNameToOpenURL (url).c_str ());
157+ }
158+
159+ TEST_METHOD (RegexMatchFirstUrlPattern1)
160+ {
161+ DefaultConfig config;
162+ config.m_urlPatterns = {
163+ { L" not-match" , L" ie" },
164+ { L" https?://.*\\ .example\\ .com/.*" , L" firefox" },
165+ { L" https?://.*\\ .example\\ .com/.*" , L" ie" },
166+ };
167+ config.m_useRegex = TRUE ;
168+ BrowserSelector app (config);
169+ wstring url (L" https://www.example.com/" );
170+ Assert::AreEqual (L" firefox" , app.GetBrowserNameToOpenURL (url).c_str ());
171+ }
172+
173+ TEST_METHOD (RegexMatchFirstUrlPattern2)
174+ {
175+ DefaultConfig config;
176+ config.m_urlPatterns = {
177+ { L" not-match" , L" ie" },
178+ { L" https?://.*\\ .example\\ .com/.*" , L" ie" },
179+ { L" https?://.*\\ .example\\ .com/.*" , L" firefox" },
180+ };
181+ config.m_useRegex = TRUE ;
182+ BrowserSelector app (config);
183+ wstring url (L" https://www.example.com/" );
184+ Assert::AreEqual (L" ie" , app.GetBrowserNameToOpenURL (url).c_str ());
185+ }
186+
187+ TEST_METHOD (WildCardMatchFirstHostNamePattern1)
188+ {
189+ DefaultConfig config;
190+ config.m_hostNamePatterns = {
191+ { L" not-match" , L" ie" },
192+ { L" www\\ .example\\ .com" , L" firefox" },
193+ { L" www\\ .example\\ .com" , L" ie" },
194+ };
195+ BrowserSelector app (config);
196+ wstring url (L" https://www.example.com/" );
197+ Assert::AreEqual (L" firefox" , app.GetBrowserNameToOpenURL (url).c_str ());
198+ }
199+
200+ TEST_METHOD (WildCardMatchFirstHostNamePattern2)
201+ {
202+ DefaultConfig config;
203+ config.m_hostNamePatterns = {
204+ { L" not-match" , L" ie" },
205+ { L" www.example.com" , L" ie" },
206+ { L" www.example.com" , L" firefox" },
207+ };
208+ BrowserSelector app (config);
209+ wstring url (L" https://www.example.com/" );
210+ Assert::AreEqual (L" ie" , app.GetBrowserNameToOpenURL (url).c_str ());
211+ }
212+
213+ TEST_METHOD (RegexMatchFirstHostNamePattern1)
214+ {
215+ DefaultConfig config;
216+ config.m_hostNamePatterns = {
217+ { L" not-match" , L" ie" },
218+ { L" www\\ .example\\ .com" , L" firefox" },
219+ { L" www\\ .example\\ .com" , L" ie" },
220+ };
221+ config.m_useRegex = TRUE ;
222+ BrowserSelector app (config);
223+ wstring url (L" https://www.example.com/" );
224+ Assert::AreEqual (L" firefox" , app.GetBrowserNameToOpenURL (url).c_str ());
225+ }
226+
227+ TEST_METHOD (RegexMatchFirstHostNamePattern2)
228+ {
229+ DefaultConfig config;
230+ config.m_hostNamePatterns = {
231+ { L" not-match" , L" ie" },
232+ { L" www\\ .example\\ .com" , L" ie" },
233+ { L" www\\ .example\\ .com" , L" firefox" },
234+ };
235+ config.m_useRegex = TRUE ;
236+ BrowserSelector app (config);
237+ wstring url (L" https://www.example.com/" );
238+ Assert::AreEqual (L" ie" , app.GetBrowserNameToOpenURL (url).c_str ());
239+ }
240+ };
80241}
81242
82243namespace TestConfig
0 commit comments