static void CreateRandomValue(ValuesFactory* pFactory, Value** ppValue, long* pSum) { int x=random(1, 10); switch(x){ case 1: { CAutoPtr<StringValue> pValue; pFactory->CreateStringValue(&pValue); pValue->SetValue(genRandString(random(0, 1)).c_str()); pValue.CopyTo((StringValue**)ppValue); } break; case 2: { CAutoPtr<BoolValue> pValue; pFactory->CreateBoolValue(&pValue); pValue->SetValue(random(0, 1)!=0); pValue.CopyTo((BoolValue**)ppValue); } break; case 3: { CAutoPtr<IntValue> pValue; pFactory->CreateIntValue(&pValue); pValue->SetValue(rand()); pValue.CopyTo((IntValue**)ppValue); } break; case 4: { CAutoPtr<LongValue> pValue; pFactory->CreateLongValue(&pValue); pValue->SetValue(rand()); pValue.CopyTo((LongValue **)ppValue); } break; case 5: { CAutoPtr<DateTimeValue> pValue; pFactory->CreateDateTimeValue(&pValue); if(random(0, 1) == 0) pValue->SetValue(time_t(random(0, SHRT_MAX))); else pValue->SetValue(-1); pValue.CopyTo((DateTimeValue **)ppValue); } break; case 6: { CAutoPtr<DateValue> pValue; pFactory->CreateDateValue(&pValue); pValue->SetValue("01-01-2001"); pValue.CopyTo((DateValue **)ppValue); } break; case 7: { CAutoPtr<BinaryValue> pValue; pFactory->CreateBinaryValue(&pValue); if(random(0, 1) == 0){ const int nSize=random(0, 32); if(nSize) pValue->SetValue(memset(alloca(nSize), 0, nSize), nSize); else pValue->SetValue(NULL, 0); } else{ const int nSize=random(1, 32); void* p=malloc(nSize); pValue->SetValue(memset(p, 0, nSize), nSize, MyFreeBufferCallback, p); }; pValue.CopyTo((BinaryValue **)ppValue); } break; case 8: { CAutoPtr<FloatValue> pValue; pFactory->CreateFloatValue(&pValue); pValue->SetValue((float)random(8191)); pValue.CopyTo((FloatValue **)ppValue); } break; case 9: { CAutoPtr<DoubleValue> pValue; pFactory->CreateDoubleValue(&pValue); pValue->SetValue(random(8191)); pValue.CopyTo((DoubleValue **)ppValue); } break; case 10: { CAutoPtr<ArrayValue> pValue; pFactory->CreateArrayValue(&pValue); const int nSize=random(0, 4); pValue->SetSize(nSize); for(int i=0; i < nSize; ++i) { CAutoPtr<Value> pValue2; CreateRandomValue(pFactory, &pValue2, pSum); pValue->SetAt(i, pValue2); }; pValue.CopyTo((ArrayValue **)ppValue); } break; default: KLSTD_ASSERT(false); }; if(pSum) ++(*pSum); };
STDMETHODIMP CopyTo(IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten) { return m_spMemStream->CopyTo(pstm, cb, pcbRead, pcbWritten); };