- Timestamp:
- Sep 11, 2018 3:37:57 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTCRest-1.cpp
r74198 r74199 32 32 #include <iprt/cpp/restarray.h> 33 33 #include <iprt/cpp/reststringmap.h> 34 #include <iprt/cpp/restclient.h> 34 35 35 36 #include <iprt/err.h> … … 1962 1963 1963 1964 1965 class TestRequest1 : public RTCRestClientRequestBase 1966 { 1967 public: 1968 RTCRestString m_strValue; 1969 RTCRestInt64 m_iValue; 1970 /** @todo add more attributes. */ 1971 1972 TestRequest1(const char *a_pszValue, int64_t a_iValue) 1973 : RTCRestClientRequestBase() 1974 , m_strValue(a_pszValue) 1975 , m_iValue(a_iValue) 1976 { 1977 m_fIsSet = UINT64_MAX; 1978 } 1979 1980 int resetToDefault() RT_OVERRIDE 1981 { 1982 m_strValue = ""; 1983 m_iValue = 0; 1984 return VINF_SUCCESS; 1985 } 1986 1987 int xmitPrepare(RTCString *a_pStrPath, RTCString *a_pStrQuery, RTHTTP a_hHttp, RTCString *a_pStrBody) const RT_OVERRIDE 1988 { 1989 RT_NOREF(a_pStrPath, a_pStrQuery, a_hHttp, a_pStrBody); 1990 return VINF_SUCCESS; 1991 } 1992 1993 void xmitComplete(int a_rcStatus, RTHTTP a_hHttp) const RT_OVERRIDE 1994 { 1995 RT_NOREF(a_rcStatus, a_hHttp); 1996 } 1997 1998 void testPath() 1999 { 2000 static PATHPARAMDESC const s_aParams[] = 2001 { 2002 { RT_STR_TUPLE("{string}"), 0, 0 }, 2003 { RT_STR_TUPLE("{integer}"), 0, 0 }, 2004 }; 2005 PATHPARAMSTATE aState[] = { { &m_strValue, 0 }, { &m_iValue, 0 } }; 2006 RTCString strPath; 2007 RTTESTI_CHECK_RC(doPathParameters(&strPath, RT_STR_TUPLE("my/{integer}/{string}/path"), 2008 s_aParams, aState, RT_ELEMENTS(aState)), VINF_SUCCESS); 2009 RTTESTI_CHECK_MSG(strPath.equals("my/123456789/this-is-a-string/path"), ("actual: '%s'\n", strPath.c_str())); 2010 } 2011 2012 void testQuery() 2013 { 2014 static QUERYPARAMDESC const s_aParams[] = 2015 { 2016 { "string", 0, true, 0 }, 2017 { "integer", 0, true, 0 }, 2018 }; 2019 RTCRestObjectBase const *apObjects[] = { &m_strValue, &m_iValue, }; 2020 RTCString strQuery; 2021 RTTESTI_CHECK_RC(doQueryParameters(&strQuery, s_aParams, apObjects, RT_ELEMENTS(apObjects)), VINF_SUCCESS); 2022 RTTESTI_CHECK_MSG(strQuery.equals("?string=this-is-a-string&integer=123456789"), ("actual: '%s'\n", strQuery.c_str())); 2023 } 2024 2025 /** @todo doHeaderParameters */ 2026 }; 2027 2028 2029 void testClientRequestBase() 2030 { 2031 RTTestSub(g_hTest, "RTCRestClientRequestBase"); 2032 2033 { 2034 TestRequest1 Req1("this-is-a-string", 123456789); 2035 Req1.testPath(); 2036 Req1.testQuery(); 2037 } 2038 } 2039 2040 1964 2041 int main() 1965 2042 { … … 1976 2053 testArray(); 1977 2054 testStringMap(); 1978 /** @todo test request & response base classes too. */ 2055 testClientRequestBase(); 2056 /** @todo test the response base class too. */ 1979 2057 1980 2058 rcExit = RTTestSummaryAndDestroy(g_hTest);
Note:
See TracChangeset
for help on using the changeset viewer.