Silence errors when assigning random values to test data
[gssweb.git] / json_gssapi / test / GSSGetMicTest.cpp
index 6600be8..e0754c3 100644 (file)
@@ -8,6 +8,8 @@
 #include "GSSGetMicTest.h"
 #include "command_mocks/MockGetMic.h"
 #include "GSSGetMic.h"
+#include <datamodel/GSSContext.h>
+#include <cache/GSSContextCache.h>
 #include <gssapi/gssapi.h>
 
 CPPUNIT_TEST_SUITE_REGISTRATION( GSSGetMicTest );
@@ -29,10 +31,8 @@ mock_get_mic(
 {
   /* Error checking */
   /* Variables */
-  std::string buffer;
   
   /* Setup */
-  buffer = MockGetMic::outputToken.toString();
   
   /* Main */
   // Copy our input from the appropriate parameters to MockGetMic
@@ -43,8 +43,7 @@ mock_get_mic(
   
   // copy our output to the appropriate parameters
   *minor_status = MockGetMic::minor_status;
-  message_token->length = buffer.length();
-  message_token->value  = (void *)buffer.c_str();
+  *message_token = *MockGetMic::outputToken.toGss();
   
   /* Cleanup */
   /* return */
@@ -82,7 +81,7 @@ void GSSGetMicTest::testEmptyCall()
   GSSBuffer input((char *)"Input message");
   std::string out("Output Message");
   gss_qop_t desiredQop = rand();
-  gss_ctx_id_t desiredContext = (gss_ctx_id_t)rand();
+  gss_ctx_id_t desiredContext = (gss_ctx_id_t)( (long)0 | rand() );
   
   /* Error checking */
   /* Setup */
@@ -130,16 +129,17 @@ void GSSGetMicTest::testEmptyCall()
 void GSSGetMicTest::testConstructorWithJSONObject()
 {
   /* Variables */
-  const char* input = "{\"method\": \"gss_get_mic\", \
-    \"arguments\": \
-    { \
-         \"context_handle\": \"#######\", \
+  GSSContext context((gss_ctx_id_t)( (long)0 | rand() ),
+                    true);
+  std::string key = GSSContextCache::instance()->store(context);
+
+  std::string input = "{ \
+         \"context_handle\": \"" + key + "\", \
          \"qop_req\": \"GSS_C_QOP_DEFAULT\", \
          \"input_message\": \"mary had a little lamb\" \
-    }\
-  }";
+    }";
   json_error_t jsonErr;
-  JSONObject json = JSONObject::load(input, 0, &jsonErr);
+  JSONObject json = JSONObject::load(input.c_str(), 0, &jsonErr);
   
   GSSGetMic cmd = GSSGetMic(&json, &mock_get_mic);
   
@@ -159,6 +159,12 @@ void GSSGetMicTest::testConstructorWithJSONObject()
     cmd.getInputMessage().toString()
   );
   
+  CPPUNIT_ASSERT_EQUAL_MESSAGE(
+    "GSSGetMic did not retrieve the context handle correctly",
+    context.getContext(),
+    cmd.getContextHandle()
+  );
+  
   /* Cleanup */
   /* Return */
 }
@@ -201,28 +207,21 @@ void GSSGetMicTest::testJSONMarshal()
 //   std::cout << "\nGSSGetMic JSON: \n" << result->dump() << "\n";
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
-    "The command name is incorrect",
-    std::string("gss_get_mic"),
-    std::string( (*result)["command"].string() )
-  );
-  
-  
-  CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The return value was reported incorrectly",
     (int)MockGetMic::retVal,
-    (int)( (*result)["return_values"]["major_status"].integer() )
+    (int)( (*result)["major_status"].integer() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The minor_status value was reported incorrectly",
     (int)MockGetMic::minor_status,
-    (int)( (*result)["return_values"]["minor_status"].integer() )
+    (int)( (*result)["minor_status"].integer() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The output message was reported incorrectly",
     output,
-    std::string( (*result)["return_values"]["output_token"].string() )
+    std::string( (*result)["output_token"].string() )
   );