void MyFn(clear__with_assoc)(SG_context * pCtx)
{
	static const SG_uint32 uSize = 100u;
	
	SG_vector* pVector = NULL;
	SG_uint32  uIndex  = 0u;
	SG_uint32  uOutput = 0u;

	VERIFY_ERR_CHECK(  SG_VECTOR__ALLOC(pCtx, &pVector, uSize)  );

	// add some allocated data to the vector
	for (uIndex = 0u; uIndex < uSize; ++uIndex)
	{
		SG_uint32* pValue = NULL;
		VERIFY_ERR_CHECK(  SG_alloc1(pCtx, pValue)  );
		*pValue = uIndex;
		VERIFY_ERR_CHECK(  SG_vector__append(pCtx, pVector, pValue, &uOutput)  );
		VERIFY_COND("Added item has unexpected index.", uOutput == uIndex);
	}

	// verify that the length is what we expect
	VERIFY_ERR_CHECK(  SG_vector__length(pCtx, pVector, &uOutput)  );
	VERIFY_COND("Vector's length doesn't match added item count.", uOutput == uSize);

	// clear the vector using our free callback
	VERIFY_ERR_CHECK(  SG_vector__clear__with_assoc(pCtx, pVector, MyFn(free_uint32))  );
	// if we get memory leaks, then the callback wasn't properly called to free the elements

	// verify that the vector is now empty
	VERIFY_ERR_CHECK(  SG_vector__length(pCtx, pVector, &uOutput)  );
	VERIFY_COND("Vector's length is non-zero after being cleared.", uOutput == 0u);

fail:
	SG_VECTOR_NULLFREE(pCtx, pVector);
}
void u0025_jsonwriter__verify(SG_context * pCtx, SG_string* pstr)
{
	const char *psz = SG_string__sz(pstr);
	SG_int32* putf32 = NULL;
	SG_uint32 len = 0;
	JSON_checker jc = new_JSON_checker(20);
	SG_uint32 i;
	int ok = 0;

	SG_utf8__to_utf32__sz(pCtx, psz, &putf32, &len);
	for (i=0; i<len; i++)
	{
		ok = JSON_checker_char(jc, putf32[i]);
		VERIFY_COND("JSON_checker_char", ok);
		if (!ok)
		{
			break;
		}
    }

	if (ok)
	{
		ok = JSON_checker_done(jc);
		VERIFY_COND("JSON_checker_done", ok);
	}


	SG_NULLFREE(pCtx, putf32);
}
void u0026_jsonparser__test_jsonparser_vhash_2(SG_context * pCtx)
{
	SG_string* pstr1 = NULL;
	SG_string* pstr2 = NULL;
	SG_vhash* pvh = NULL;

	VERIFY_ERR_CHECK(  SG_STRING__ALLOC(pCtx, &pstr1)  );
	VERIFY_ERR_CHECK(  SG_STRING__ALLOC(pCtx, &pstr2)  );

	VERIFY_ERR_CHECK(  u0026_jsonparser__create_2(pCtx, pstr1)  );

	SG_VHASH__ALLOC__FROM_JSON__SZ(pCtx, &pvh, SG_string__sz(pstr1));
	VERIFY_COND("from_json", !SG_context__has_err(pCtx));
	VERIFY_COND("from_json", pvh);

	SG_context__err_reset(pCtx);
	SG_vhash__to_json(pCtx, pvh, pstr2);
	VERIFY_COND("from_json", !SG_context__has_err(pCtx));

	// TODO do some checks

fail:
	SG_STRING_NULLFREE(pCtx, pstr1);
	SG_STRING_NULLFREE(pCtx, pstr2);
	SG_VHASH_NULLFREE(pCtx, pvh);
}
void MyFn(test_W2771)(SG_context * pCtx)
{
	SG_vector_i64 * pVec = NULL;
	SG_int64 i64 = 0x123456789abcdefLL;
	SG_uint32 len;

	// allocate a vector with a hint of at least 1 cell.
	// (the minimum chunk size will override this, but we don't care.)
	VERIFY_ERR_CHECK(  SG_vector_i64__alloc(pCtx,&pVec,1)  );

	// verify size-in-use is 0.
	VERIFY_ERR_CHECK(  SG_vector_i64__length(pCtx,pVec,&len)  );
	VERIFY_COND("test1",(len==0));

	// do a hard-reserve with zero-fill of the vector.
	// (we pick a size larger than any pre-defined chunk size.)
	VERIFY_ERR_CHECK(  SG_vector_i64__reserve(pCtx, pVec, 1000)  );
	VERIFY_ERR_CHECK(  SG_vector_i64__get(pCtx, pVec, 999, &i64)  );
	VERIFY_COND("get[1000]", (i64 == 0));

	VERIFY_ERR_CHECK(  SG_vector_i64__length(pCtx,pVec,&len)  );
	VERIFY_COND("test1",(len==1000));

fail:
	SG_VECTOR_I64_NULLFREE(pCtx, pVec);
}
Example #5
0
void MyFn(create_zero_byte_blob)(SG_context* pCtx,
								 SG_repo* pRepo)
{
	struct z
	{
		const char * pszHashMethod;
		const char * pszTrivialHash;
	};
	struct z az[] = { { "SHA1/160", 	"da39a3ee5e6b4b0d3255bfef95601890afd80709" },
					  { "SHA2/256",		"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" },
					  { "SHA2/384",		"38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b" },
					  { "SHA2/512",		"cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" },
	};

	char* pszidHidBlob1 = NULL;
	char * pbuf1 = NULL;
	char * pbuf2 = NULL;
	SG_uint64 lenBuf2;
	SG_repo_tx_handle* pTx = NULL;
	SG_uint32 lenBuf1 = 0;
	char * pszHashMethod = NULL;
	SG_uint32 k, kLimit;

	pbuf1 = (char *)SG_calloc(1,lenBuf1+1);

	VERIFY_ERR_CHECK_DISCARD(  SG_repo__begin_tx(pCtx, pRepo, &pTx)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_repo__store_blob_from_memory(pCtx, pRepo,pTx,NULL,SG_FALSE,(SG_byte *)pbuf1,lenBuf1,&pszidHidBlob1)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_repo__commit_tx(pCtx, pRepo, &pTx)  );

	INFOP("create_zero_byte_blob",("Created blob [%s]",(pszidHidBlob1)));

		//////////////////////////////////////////////////////////////////
	// fetch blob into a new buffer and verify that it matches.

	VERIFY_ERR_CHECK_DISCARD(  SG_repo__fetch_blob_into_memory(pCtx, pRepo,pszidHidBlob1,(SG_byte **)&pbuf2,&lenBuf2)  );
	VERIFY_COND("create_zero_byte_blob(fetch blob)",(lenBuf2 == (SG_uint64)lenBuf1));

	VERIFY_COND("create_zero_byte_blob(memcmp)",(memcmp(pbuf1,pbuf2,lenBuf1)==0));

	VERIFY_ERR_CHECK_DISCARD(  SG_repo__get_hash_method(pCtx, pRepo, &pszHashMethod)  );
	kLimit = SG_NrElements(az);
	for (k=0; k<kLimit; k++)
	{
		if (strcmp(pszHashMethod,az[k].pszHashMethod) == 0)
		{
			// The empty blob should always have this hid
			VERIFY_COND("zero byte blob hid mismatch",
						strcmp(pszidHidBlob1, az[k].pszTrivialHash) == 0);
		}
	}

	//////////////////////////////////////////////////////////////////
	// cleanup

	SG_NULLFREE(pCtx, pbuf1);
	SG_NULLFREE(pCtx, pbuf2);
	SG_NULLFREE(pCtx, pszidHidBlob1);
	SG_NULLFREE(pCtx, pszHashMethod);
}
Example #6
0
void u0048_multidag_test__1(SG_context * pCtx)
{
	char bufName[SG_TID_MAX_BUFFER_LENGTH + u0048_multidag__MY_LABEL_LENGTH];
    SG_repo* pRepo = NULL;
    SG_rbtree* prb = NULL;
    SG_uint32 count;

    char* pid1 = NULL;
    char* pid1a = NULL;
    char* pid1b = NULL;
    char* pid1c = NULL;

    char* pid2 = NULL;
    char* pid2a = NULL;
    char* pid2b = NULL;

	VERIFY_ERR_CHECK(  SG_strcpy(pCtx, bufName, sizeof(bufName), u0048_multidag__MY_LABEL)  );
	VERIFY_ERR_CHECK(  SG_tid__generate2(pCtx, &bufName[u0048_multidag__MY_LABEL_LENGTH], (sizeof(bufName) - u0048_multidag__MY_LABEL_LENGTH), 32)  );

    /* create the repo */
	VERIFY_ERR_CHECK(  u0048_multidag__new_repo(pCtx, bufName, &pRepo)  );

    VERIFY_ERR_CHECK(  u0048_multidag__add_dagnode(pCtx, &pid1, NULL, SG_DAGNUM__TESTING__NOTHING, pRepo)  );
    VERIFY_ERR_CHECK(  u0048_multidag__add_dagnode(pCtx, &pid1a, pid1, SG_DAGNUM__TESTING__NOTHING, pRepo)  );
    VERIFY_ERR_CHECK(  u0048_multidag__add_dagnode(pCtx, &pid1b, pid1, SG_DAGNUM__TESTING__NOTHING, pRepo)  );
    VERIFY_ERR_CHECK(  u0048_multidag__add_dagnode(pCtx, &pid1c, pid1, SG_DAGNUM__TESTING__NOTHING, pRepo)  );

    VERIFY_ERR_CHECK(  u0048_multidag__add_dagnode(pCtx, &pid2, NULL, SG_DAGNUM__TESTING2__NOTHING, pRepo)  );
    VERIFY_ERR_CHECK(  u0048_multidag__add_dagnode(pCtx, &pid2a, pid2, SG_DAGNUM__TESTING2__NOTHING, pRepo)  );
    VERIFY_ERR_CHECK(  u0048_multidag__add_dagnode(pCtx, &pid2b, pid2, SG_DAGNUM__TESTING2__NOTHING, pRepo)  );

    SG_NULLFREE(pCtx, pid1);
    SG_NULLFREE(pCtx, pid1a);
    SG_NULLFREE(pCtx, pid1b);
    SG_NULLFREE(pCtx, pid1c);

    SG_NULLFREE(pCtx, pid2);
    SG_NULLFREE(pCtx, pid2a);
    SG_NULLFREE(pCtx, pid2b);

    VERIFY_ERR_CHECK(  SG_repo__fetch_dag_leaves(pCtx, pRepo, SG_DAGNUM__TESTING__NOTHING, &prb)  );
    VERIFY_ERR_CHECK(  SG_rbtree__count(pCtx, prb, &count)  );
    SG_RBTREE_NULLFREE(pCtx, prb);
    VERIFY_COND("count", (3 == count));

    VERIFY_ERR_CHECK(  SG_repo__fetch_dag_leaves(pCtx, pRepo, SG_DAGNUM__TESTING2__NOTHING, &prb)  );
    VERIFY_ERR_CHECK(  SG_rbtree__count(pCtx, prb, &count)  );
    SG_RBTREE_NULLFREE(pCtx, prb);
    VERIFY_COND("count", (2 == count));

	SG_REPO_NULLFREE(pCtx, pRepo);

	return;

fail:
	SG_REPO_NULLFREE(pCtx, pRepo);
}
void u0026_jcb(SG_UNUSED_PARAM(SG_context* pCtx), void* ctx, int type, const SG_jsonparser_value* value)
{
	struct u0026_ctx* p = (struct u0026_ctx*) ctx;

	SG_UNUSED(pCtx);

    switch(type) {
    case SG_JSONPARSER_TYPE_ARRAY_BEGIN:
		p->key[0] = 0;
        break;
    case SG_JSONPARSER_TYPE_ARRAY_END:
		p->key[0] = 0;
        break;
	case SG_JSONPARSER_TYPE_OBJECT_BEGIN:
		p->key[0] = 0;
        break;
    case SG_JSONPARSER_TYPE_OBJECT_END:
		p->key[0] = 0;
        break;
    case SG_JSONPARSER_TYPE_INTEGER:
		if (0 == strcmp(p->key, "x"))
		{
			VERIFY_COND("x", 5 == value->vu.integer_value);
		}
		p->key[0] = 0;
        break;
    case SG_JSONPARSER_TYPE_FLOAT:
		p->key[0] = 0;
        break;
    case SG_JSONPARSER_TYPE_NULL:
		p->key[0] = 0;
        break;
    case SG_JSONPARSER_TYPE_TRUE:
		p->key[0] = 0;
        break;
    case SG_JSONPARSER_TYPE_FALSE:
		p->key[0] = 0;
        break;
    case SG_JSONPARSER_TYPE_KEY:
		strcpy(p->key, value->vu.str.value);
        break;
    case SG_JSONPARSER_TYPE_STRING:
		if (0 == strcmp(p->key, "hello"))
		{
			VERIFY_COND("hello:world", 0 == strcmp("world", value->vu.str.value));
		}
		else if (0 == strcmp(p->key, "messy"))
		{
			VERIFY_COND("messy", 0 == strcmp(U0026_MESSY, value->vu.str.value));
		}
		p->key[0] = 0;
        break;
    default:
        SG_ASSERT(0);
        break;
    }
}
Example #8
0
void u0051_hidlookup_test__1(SG_context * pCtx, SG_pathname* pPathTopDir)
{
	char bufName[SG_TID_MAX_BUFFER_LENGTH];
	SG_pathname* pPathWorkingDir = NULL;
	SG_pathname* pPathFile = NULL;
    SG_dagnode* pdn = NULL;
    const char* psz_hid_cs = NULL;
    SG_repo* pRepo = NULL;
    char buf_partial[256];
    char* psz_result = NULL;
    SG_audit q;

	VERIFY_ERR_CHECK(  SG_tid__generate2(pCtx, bufName, sizeof(bufName), 32)  );

	/* create the working dir */
	VERIFY_ERR_CHECK(  SG_PATHNAME__ALLOC__PATHNAME_SZ(pCtx, &pPathWorkingDir, pPathTopDir, bufName)  );
	VERIFY_ERR_CHECK(  SG_fsobj__mkdir__pathname(pCtx, pPathWorkingDir)  );

    /* add stuff */
	VERIFY_ERR_CHECK(  u0051_hidlookup__create_file__numbers(pCtx, pPathWorkingDir, "aaa", 20)  );

    /* create the repo */
	VERIFY_ERR_CHECK(  _ut_pt__new_repo(pCtx, bufName, pPathWorkingDir)  );
	VERIFY_ERR_CHECK(  _ut_pt__addremove(pCtx, pPathWorkingDir)  );
	VERIFY_ERR_CHECK(  u0051_hidlookup__commit_all(pCtx, pPathWorkingDir, &pdn)  );

    VERIFY_ERR_CHECK(  SG_dagnode__get_id_ref(pCtx, pdn, &psz_hid_cs)  );

	VERIFY_ERR_CHECK(  SG_repo__open_repo_instance(pCtx, bufName, &pRepo)  );

    VERIFY_ERR_CHECK(  SG_audit__init(pCtx, &q, pRepo, SG_AUDIT__WHEN__NOW, SG_AUDIT__WHO__FROM_SETTINGS)  );
    VERIFY_ERR_CHECK(  SG_vc_tags__add(pCtx, pRepo, psz_hid_cs, "remember", &q)  );

    VERIFY_ERR_CHECK(  SG_strcpy(pCtx, buf_partial, sizeof(buf_partial), psz_hid_cs)  );
    buf_partial[10] = 0;

	VERIFY_ERR_CHECK(  SG_repo__hidlookup__dagnode(pCtx, pRepo, SG_DAGNUM__VERSION_CONTROL, buf_partial, &psz_result)  );
    VERIFY_COND("found", (0 == strcmp(psz_result, psz_hid_cs)));
    SG_NULLFREE(pCtx, psz_result);

    VERIFY_ERR_CHECK(  SG_repo__hidlookup__blob(pCtx, pRepo, buf_partial, &psz_result)  );
    VERIFY_COND("found", (0 == strcmp(psz_result, psz_hid_cs)));
    SG_NULLFREE(pCtx, psz_result);

	VERIFY_ERR_CHECK(  SG_vc_tags__lookup__tag(pCtx, pRepo, "remember", &psz_result)  );
    VERIFY_COND("found", (0 == strcmp(psz_result, psz_hid_cs)));
    SG_NULLFREE(pCtx, psz_result);

fail:
    SG_NULLFREE(pCtx, psz_result);
    SG_REPO_NULLFREE(pCtx, pRepo);
    SG_DAGNODE_NULLFREE(pCtx, pdn);
	SG_PATHNAME_NULLFREE(pCtx, pPathWorkingDir);
	SG_PATHNAME_NULLFREE(pCtx, pPathFile);
}
void MyFn(one_dagnode)(SG_context * pCtx, SG_repo* pRepo)
{
	char* pId = NULL;
	SG_dagnode* pdnCreated = NULL;
	SG_dagnode* pdnFetched = NULL;
	SG_repo_tx_handle* pTx = NULL;
	char buf_tid[SG_TID_MAX_BUFFER_LENGTH];

	VERIFY_ERR_CHECK(  SG_tid__generate(pCtx, buf_tid, sizeof(buf_tid))  );
	VERIFY_ERR_CHECK(  SG_repo__alloc_compute_hash__from_bytes(pCtx,
															   pRepo,
															   sizeof(buf_tid),
															   (SG_byte *)buf_tid,
															   &pId)  );

	VERIFY_ERR_CHECK(  SG_dagnode__alloc(pCtx, &pdnCreated, pId, 1, 0)  );
	VERIFY_ERR_CHECK(  SG_dagnode__freeze(pCtx, pdnCreated)  );

	// Add dagnode.
	VERIFY_ERR_CHECK(  SG_repo__begin_tx(pCtx, pRepo, &pTx)  );
	VERIFY_ERR_CHECK(  SG_repo__store_dagnode(pCtx, pRepo, pTx, SG_DAGNUM__TESTING__NOTHING, pdnCreated)  );
    pdnCreated = NULL;

	// Should fail: tx not committed.
	VERIFY_ERR_CHECK_ERR_EQUALS_DISCARD(  SG_repo__fetch_dagnode(pCtx, pRepo, SG_DAGNUM__TESTING__NOTHING, pId, &pdnFetched),
										  SG_ERR_NOT_FOUND  );	// Dag node visible before repo tx committed.

	// Abort repo tx.
	VERIFY_ERR_CHECK(  SG_repo__abort_tx(pCtx, pRepo, &pTx)  );
	VERIFY_COND("SG_repo__abort_tx should null/free the repo transaction.", !pTx);

	// Should fail: tx aborted.
	VERIFY_ERR_CHECK_ERR_EQUALS_DISCARD(  SG_repo__fetch_dagnode(pCtx, pRepo, SG_DAGNUM__TESTING__NOTHING, pId, &pdnFetched),
										  SG_ERR_NOT_FOUND  ); // Dag node exists after repo tx abort

	// Write dagnode, commit tx.
	VERIFY_ERR_CHECK(  SG_repo__begin_tx(pCtx, pRepo, &pTx)  );
	VERIFY_ERR_CHECK(  SG_dagnode__alloc(pCtx, &pdnCreated, pId, 1, 0)  );
	VERIFY_ERR_CHECK(  SG_dagnode__freeze(pCtx, pdnCreated)  );
	VERIFY_ERR_CHECK(  SG_repo__store_dagnode(pCtx, pRepo, pTx, SG_DAGNUM__TESTING__NOTHING, pdnCreated)  );
    pdnCreated = NULL;
	VERIFY_ERR_CHECK(  SG_repo__commit_tx(pCtx, pRepo, &pTx)  );
	VERIFY_COND("SG_repo__commit_tx should null/free the repo transaction.", !pTx);

	// Read back the dagnode.  It should exist now.
	VERIFY_ERR_CHECK(  SG_repo__fetch_dagnode(pCtx, pRepo, SG_DAGNUM__TESTING__NOTHING, pId, &pdnFetched)  );

	// Fall through to common cleanup.

fail:
	SG_NULLFREE(pCtx, pId);
	SG_DAGNODE_NULLFREE(pCtx, pdnCreated);
	SG_DAGNODE_NULLFREE(pCtx, pdnFetched);
}
// Store a blob.  Make sure it doesn't show up until/unless the repo tx is committed.
void MyFn(one_blob)(SG_context * pCtx, SG_repo* pRepo)
{
	SG_byte* pBufIn = NULL;
	SG_uint32 lenBufIn = 0;

	SG_byte* pBufOut = NULL;
	SG_uint64 lenBufOut = 0;

	SG_repo_tx_handle* pTx;
	char* pszHidReturned = NULL;

	VERIFY_ERR_CHECK(  MyFn(alloc_random_buffer)(pCtx, &pBufIn, &lenBufIn)  );

	// Start writing blob.
	VERIFY_ERR_CHECK(  SG_repo__begin_tx(pCtx, pRepo, &pTx)  );
	VERIFY_ERR_CHECK(  SG_repo__store_blob_from_memory(pCtx, pRepo, pTx, SG_FALSE, pBufIn, lenBufIn, &pszHidReturned)  );

	// Should fail: tx not committed.
	VERIFY_ERR_CHECK_ERR_EQUALS_DISCARD(  SG_repo__fetch_blob_into_memory(pCtx, pRepo, pszHidReturned, &pBufOut, &lenBufOut),
										  SG_ERR_BLOB_NOT_FOUND  );			// Blob visible before repo tx committed
	SG_NULLFREE(pCtx, pBufOut);

	// Abort repo tx.
	VERIFY_ERR_CHECK(  SG_repo__abort_tx(pCtx, pRepo, &pTx)  );
	VERIFY_COND("SG_repo__abort_tx should null/free the repo transaction.", !pTx);

	// Should fail: tx aborted.
	VERIFY_ERR_CHECK_ERR_EQUALS_DISCARD(  SG_repo__fetch_blob_into_memory(pCtx, pRepo, pszHidReturned, &pBufOut, &lenBufOut),
										  SG_ERR_BLOB_NOT_FOUND  );			// Blob exists after repo tx abort
	SG_NULLFREE(pCtx, pBufOut);

	SG_NULLFREE(pCtx, pszHidReturned);

	// Write blob, commit tx.
	VERIFY_ERR_CHECK(  SG_repo__begin_tx(pCtx, pRepo, &pTx)  );
	VERIFY_ERR_CHECK(  SG_repo__store_blob_from_memory(pCtx, pRepo, pTx, SG_FALSE, pBufIn, lenBufIn, &pszHidReturned)  );
	VERIFY_ERR_CHECK(  SG_repo__commit_tx(pCtx, pRepo, &pTx)  );
	VERIFY_COND("SG_repo__commit_tx should null/free the repo transaction.", !pTx);

	// Read back the blob.  It should exist now.
	VERIFY_ERR_CHECK(  SG_repo__fetch_blob_into_memory(pCtx, pRepo, pszHidReturned, &pBufOut, &lenBufOut)  );
	// Just verify the length.  It's another test's job to roundtrip blobs and verify data.
	VERIFY_COND(  "blob length mismatch", lenBufOut == lenBufIn  );

	 // Fall through to common cleanup.

fail:
	SG_NULLFREE(pCtx, pszHidReturned);
	SG_NULLFREE(pCtx, pBufIn);
	SG_NULLFREE(pCtx, pBufOut);
}
void MyFn(alloc__copy__deep)(SG_context * pCtx)
{
	static const SG_uint32 uSize = 100u;
	
	SG_vector* pVector  = NULL;
	SG_vector* pCopy    = NULL;
	SG_uint32  uIndex   = 0u;
	SG_uint32  uOutput1 = 0u;
	SG_uint32  uOutput2 = 0u;
	void*      pOutput1 = NULL;
	void*      pOutput2 = NULL;

	VERIFY_ERR_CHECK(  SG_VECTOR__ALLOC(pCtx, &pVector, uSize)  );

	// add some allocated data to the vector
	for (uIndex = 0u; uIndex < uSize; ++uIndex)
	{
		SG_uint32* pValue = NULL;
		VERIFY_ERR_CHECK(  SG_alloc1(pCtx, pValue)  );
		*pValue = uIndex;
		VERIFY_ERR_CHECK(  SG_vector__append(pCtx, pVector, pValue, &uOutput1)  );
		VERIFY_COND("Added item has unexpected index.", uOutput1 == uIndex);
	}

	// copy the vector
	VERIFY_ERR_CHECK(  SG_VECTOR__ALLOC__COPY(pCtx, pVector, MyFn(copy_uint32), MyFn(free_uint32), &pCopy)  );

	// verify that the copy matches the original
	VERIFY_ERR_CHECK(  SG_vector__length(pCtx, pVector, &uOutput1)  );
	VERIFY_ERR_CHECK(  SG_vector__length(pCtx, pCopy,   &uOutput2)  );
	VERIFY_COND("Copied vector's length doesn't match added item count.", uOutput1 == uSize);
	VERIFY_COND("Copied vector's length doesn't match original.", uOutput1 == uOutput2);
	for (uIndex = 0u; uIndex < uOutput1; ++uIndex)
	{
		VERIFY_ERR_CHECK(  SG_vector__get(pCtx, pVector, uIndex, &pOutput1)  );
		VERIFY_ERR_CHECK(  SG_vector__get(pCtx, pCopy,   uIndex, &pOutput2)  );
		VERIFYP_COND("Copied vector's pointer value matches original after deep copy.", pOutput1 != pOutput2, ("index(%d)", uIndex));
		uOutput1 = *((SG_uint32*)pOutput1);
		uOutput2 = *((SG_uint32*)pOutput2);
		VERIFYP_COND("Copied vector's pointed-to value doesn't match original after deep copy.", uOutput1 == uOutput2, ("index(%d)", uIndex));
	}

fail:
	SG_context__push_level(pCtx);
	SG_vector__free__with_assoc(pCtx, pVector, MyFn(free_uint32));
	SG_vector__free__with_assoc(pCtx, pCopy,   MyFn(free_uint32));
	SG_context__pop_level(pCtx);
}
void u0052_zip__test_2(SG_context * pCtx)
{
    const char* psz_text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

    SG_uint32 len_orig = SG_STRLEN(psz_text) + 1;
    SG_byte* p_compressed = NULL;
    SG_byte* p_uncompressed = NULL;
    SG_uint32 len_compressed = 0;

    SG_ERR_CHECK(  SG_zlib__deflate__memory(
                pCtx, 
                (SG_byte*) psz_text,
                len_orig,
                &p_compressed,
                &len_compressed
                )  );

    SG_ERR_CHECK(  SG_allocN(pCtx, len_orig, p_uncompressed)  );
    SG_ERR_CHECK(  SG_zlib__inflate__memory(
                pCtx,
                p_compressed,
                len_compressed,
                p_uncompressed,
                len_orig
                )  );

    VERIFY_COND("name", (0 == strcmp(psz_text, (char*) p_uncompressed)));

fail:
    SG_NULLFREE(pCtx, p_compressed);
    SG_NULLFREE(pCtx, p_uncompressed);
}
Example #13
0
void u0038_test_wdmapping(SG_context * pCtx)
{
	SG_vhash* pvh = NULL;
	SG_pathname* pPath = NULL;
	SG_pathname* pMappedPath = NULL;
	SG_string* pstrRepoDescriptorName = NULL;
	char* pszidGid = NULL;

	VERIFY_ERR_CHECK_DISCARD(  SG_PATHNAME__ALLOC(pCtx, &pPath)  );

	VERIFY_ERR_CHECK_DISCARD(  SG_pathname__set__from_cwd(pCtx, pPath)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_VHASH__ALLOC(pCtx, &pvh)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_vhash__add__string__sz(pCtx, pvh, "hello", "world")  );
	VERIFY_ERR_CHECK_DISCARD(  SG_vhash__add__string__sz(pCtx, pvh, "hola", "mundo")  );
	SG_ERR_IGNORE(  SG_closet__descriptors__remove(pCtx, "r1")  );
	VERIFY_ERR_CHECK_DISCARD(  SG_closet__descriptors__add(pCtx, "r1", pvh)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_workingdir__set_mapping(pCtx, pPath, "r1", NULL)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_workingdir__find_mapping(pCtx, pPath, &pMappedPath, &pstrRepoDescriptorName, &pszidGid)  );
	VERIFY_COND("ridesc match", (0 == strcmp("r1", SG_string__sz(pstrRepoDescriptorName))));
	VERIFY_ERR_CHECK_DISCARD(  SG_pathname__append__from_sz(pCtx, pPath, "foo")  );
	VERIFY_ERR_CHECK_DISCARD(  SG_pathname__append__from_sz(pCtx, pPath, "bar")  );
	VERIFY_ERR_CHECK_DISCARD(  SG_pathname__append__from_sz(pCtx, pPath, "plok")  );

	SG_STRING_NULLFREE(pCtx, pstrRepoDescriptorName);
	SG_PATHNAME_NULLFREE(pCtx, pMappedPath);

	VERIFY_ERR_CHECK_DISCARD(  SG_workingdir__find_mapping(pCtx, pPath, &pMappedPath, &pstrRepoDescriptorName, &pszidGid)  );

	SG_STRING_NULLFREE(pCtx, pstrRepoDescriptorName);
	SG_PATHNAME_NULLFREE(pCtx, pMappedPath);
	SG_PATHNAME_NULLFREE(pCtx, pPath);

	SG_VHASH_NULLFREE(pCtx, pvh);
}
void _verify_value(
	SG_context* pCtx,
	SG_uint32   uIndex,
	void*       pData,
	void*       pUserData
	)
{
	_verify_value_data* pValueData = (_verify_value_data*)pUserData;

	SG_UNUSED(pCtx);

	VERIFY_COND("Value found at wrong index.", uIndex == pValueData->uExpectedIndex);
	VERIFY_COND("Wrong value found.", strcmp((const char*)pData, pValueData->szExpectedValue) == 0);

	pValueData->uExpectedIndex += pValueData->uMiddleIndex;
}
void u0038_test_wdmapping(SG_context * pCtx)
{
	SG_vhash* pvh = NULL;
	SG_closet_descriptor_handle* ph = NULL;
	SG_pathname* pPath = NULL;
	SG_pathname* pMappedPath = NULL;
	SG_string* pstrRepoDescriptorName = NULL;
	char* pszidGid = NULL;
	char buf_tid[SG_TID_MAX_BUFFER_LENGTH];

	VERIFY_ERR_CHECK_DISCARD(  SG_tid__generate2__suffix(pCtx, buf_tid, sizeof(buf_tid), 32, "u0038")  );
	VERIFY_ERR_CHECK_DISCARD(  SG_PATHNAME__ALLOC__SZ(pCtx, &pPath, buf_tid)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_fsobj__mkdir__pathname(pCtx, pPath)  );

	SG_ERR_IGNORE(  SG_closet__descriptors__remove(pCtx, "r1")  );
	VERIFY_ERR_CHECK_DISCARD(  SG_closet__descriptors__add_begin(pCtx, "r1", NULL, NULL, NULL, NULL, &pvh, &ph)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_closet__descriptors__add_commit(pCtx, &ph, pvh, SG_REPO_STATUS__NORMAL)  );
	SG_VHASH_NULLFREE(pCtx, pvh);
	VERIFY_ERR_CHECK_DISCARD(  SG_workingdir__set_mapping(pCtx, pPath, "r1", NULL)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_workingdir__find_mapping(pCtx, pPath, &pMappedPath, &pstrRepoDescriptorName, &pszidGid)  );
	VERIFY_COND("ridesc match", (0 == strcmp("r1", SG_string__sz(pstrRepoDescriptorName))));
	VERIFY_ERR_CHECK_DISCARD(  SG_pathname__append__from_sz(pCtx, pPath, "foo")  );
	VERIFY_ERR_CHECK_DISCARD(  SG_pathname__append__from_sz(pCtx, pPath, "bar")  );
	VERIFY_ERR_CHECK_DISCARD(  SG_pathname__append__from_sz(pCtx, pPath, "plok")  );

	SG_STRING_NULLFREE(pCtx, pstrRepoDescriptorName);
	SG_PATHNAME_NULLFREE(pCtx, pMappedPath);

	VERIFY_ERR_CHECK_DISCARD(  SG_workingdir__find_mapping(pCtx, pPath, &pMappedPath, &pstrRepoDescriptorName, &pszidGid)  );

	SG_STRING_NULLFREE(pCtx, pstrRepoDescriptorName);
	SG_PATHNAME_NULLFREE(pCtx, pMappedPath);
	SG_PATHNAME_NULLFREE(pCtx, pPath);
}
void u0038_test_ridesc(SG_context * pCtx)
{
	SG_closet_descriptor_handle* ph = NULL;
	SG_vhash* pvh = NULL;
	SG_vhash* pvh_all = NULL;
	SG_uint32 count = 0;

	SG_ERR_IGNORE(  SG_closet__descriptors__remove(pCtx, "1")  );
	VERIFY_ERR_CHECK_DISCARD(  SG_closet__descriptors__add_begin(pCtx, "1", NULL, NULL, NULL, NULL, &pvh, &ph)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_closet__descriptors__add_commit(pCtx, &ph, pvh, SG_REPO_STATUS__NORMAL));
	SG_VHASH_NULLFREE(pCtx, pvh);
	VERIFY_ERR_CHECK_DISCARD(  SG_closet__descriptors__remove(pCtx, "1")  );

	SG_ERR_IGNORE(  SG_closet__descriptors__remove(pCtx, "2")  );		/* This may or may not be an error */

	/* delete one that is not there should be an error */
	VERIFY_ERR_CHECK_HAS_ERR_DISCARD(  SG_closet__descriptors__remove(pCtx, "2")  );

	/* fetch one that is not there should be an error */
	VERIFY_ERR_CHECK_HAS_ERR_DISCARD(  SG_closet__descriptors__get(pCtx, "2", NULL, &pvh)  );
	VERIFY_COND("", pvh==NULL);

	SG_ERR_IGNORE(  SG_closet__descriptors__remove(pCtx, "3")  );
	SG_ERR_IGNORE(  SG_closet__descriptors__remove(pCtx, "4")  );
	VERIFY_ERR_CHECK_DISCARD(  SG_closet__descriptors__add_begin(pCtx, "3", NULL, NULL, NULL, NULL, &pvh, &ph)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_closet__descriptors__add_commit(pCtx, &ph, pvh, SG_REPO_STATUS__NORMAL)  );
	SG_VHASH_NULLFREE(pCtx, pvh);
	VERIFY_ERR_CHECK_DISCARD(  SG_closet__descriptors__add_begin(pCtx, "4", NULL, NULL, NULL, NULL, &pvh, &ph)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_closet__descriptors__add_commit(pCtx, &ph, pvh, SG_REPO_STATUS__NORMAL)  );
	SG_VHASH_NULLFREE(pCtx, pvh);
	
	VERIFY_ERR_CHECK_DISCARD(  SG_closet__descriptors__get(pCtx, "3", NULL, &pvh)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_closet__descriptors__list(pCtx, &pvh_all)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_vhash__count(pCtx, pvh_all, &count)  );

	/* adding a duplicate name should be an error */
	VERIFY_ERR_CHECK_ERR_EQUALS_DISCARD(
		SG_closet__descriptors__add_begin(pCtx, "3", NULL, NULL, NULL, NULL, NULL, &ph), 
		SG_ERR_REPO_ALREADY_EXISTS);

	VERIFY_COND("count", (count >= 2));
	SG_ERR_IGNORE(  SG_closet__descriptors__remove(pCtx, "3")  );
	SG_ERR_IGNORE(  SG_closet__descriptors__remove(pCtx, "4")  );

	SG_VHASH_NULLFREE(pCtx, pvh_all);
	SG_VHASH_NULLFREE(pCtx, pvh);
}
int u0001_stdint__test_system(void)
{
	VERIFY_COND( "test_system", (sizeof(size_t) >= 4) );
#if defined(LINUX) || defined(MAC)
	INFOP("test_system", ("sizeof(off_t) is %d",(SG_uint32)sizeof(off_t)));
#endif

	return 1;
}
static void _add_conflicting_descriptor_in_thread(void* pParam)
#endif
{
	thread_data* pMe = (thread_data*)pParam;
	SG_context* pCtx = pMe->pCtx;
	SG_closet_descriptor_handle* ph = NULL;
	SG_vhash* pvh = NULL;

	VERIFY_ERR_CHECK_ERR_EQUALS_DISCARD(SG_closet__descriptors__add_begin(pCtx, "1", NULL, NULL, NULL, NULL, &pvh, &ph),
		SG_ERR_REPO_ALREADY_EXISTS);
	VERIFY_COND("", !pvh);
	VERIFY_COND("", !ph);

	SG_VHASH_NULLFREE(pCtx, pvh);
	SG_ERR_IGNORE(SG_closet__descriptors__add_abort(pCtx, &ph));

#if defined(WINDOWS)
	return (SG_context__has_err(pCtx));
#endif
}
void MyFn(alloc__copy__shallow)(SG_context * pCtx)
{
	static const SG_uint32 uSize = 100u;
	
	SG_vector* pVector  = NULL;
	SG_vector* pCopy    = NULL;
	SG_uint32  uIndex   = 0u;
	SG_uint32  uOutput1 = 0u;
	SG_uint32  uOutput2 = 0u;
	void*      pOutput1 = NULL;
	void*      pOutput2 = NULL;

	VERIFY_ERR_CHECK(  SG_VECTOR__ALLOC(pCtx, &pVector, uSize)  );

	// add some random stack data to the vector
	for (uIndex = 0u; uIndex < uSize; ++uIndex)
	{
		VERIFY_ERR_CHECK(  SG_vector__append(pCtx, pVector, &uIndex + uIndex, &uOutput1)  );
		VERIFY_COND("Added item has unexpected index.", uOutput1 == uIndex);
	}

	// copy the vector
	VERIFY_ERR_CHECK(  SG_VECTOR__ALLOC__COPY(pCtx, pVector, NULL, NULL, &pCopy)  );

	// verify that the copy matches the original
	VERIFY_ERR_CHECK(  SG_vector__length(pCtx, pVector, &uOutput1)  );
	VERIFY_ERR_CHECK(  SG_vector__length(pCtx, pCopy,   &uOutput2)  );
	VERIFY_COND("Copied vector's length doesn't match added item count.", uOutput1 == uSize);
	VERIFY_COND("Copied vector's length doesn't match original.", uOutput1 == uOutput2);
	for (uIndex = 0u; uIndex < uOutput1; ++uIndex)
	{
		VERIFY_ERR_CHECK(  SG_vector__get(pCtx, pVector, uIndex, &pOutput1)  );
		VERIFY_ERR_CHECK(  SG_vector__get(pCtx, pCopy,   uIndex, &pOutput2)  );
		VERIFYP_COND("Copied vector's value doesn't match original.", pOutput1 == pOutput2, ("index(%d", uIndex));
	}

fail:
	SG_VECTOR_NULLFREE(pCtx, pVector);
	SG_VECTOR_NULLFREE(pCtx, pCopy);
}
int u0001_stdint__test_scalars(void)
{
	VERIFY_COND( "test_scalars", (sizeof(SG_int8) == 1) );
	VERIFY_COND( "test_scalars", (sizeof(SG_uint8) == 1) );

	VERIFY_COND( "test_scalars", (sizeof(SG_int16) == 2) );
	VERIFY_COND( "test_scalars", (sizeof(SG_uint16) == 2) );

	VERIFY_COND( "test_scalars", (sizeof(SG_int32) == 4) );
	VERIFY_COND( "test_scalars", (sizeof(SG_uint32) == 4) );

	VERIFY_COND( "test_scalars", (sizeof(SG_int64) == 8) );
	VERIFY_COND( "test_scalars", (sizeof(SG_uint64) == 8) );

	VERIFY_COND( "test_scalars", (sizeof(SG_byte) == 1) );

	return 1;
}
MyMain()
{
	TEMPLATE_MAIN_START;

#if defined(MAC) || defined(LINUX)
	BEGIN_TEST(  MyFn(test1)(pCtx)  );
	BEGIN_TEST(  MyFn(test2)(pCtx)  );
#else
	VERIFY_COND("Skipping test on Windows platform...", SG_TRUE);
#endif

	TEMPLATE_MAIN_END;
}
void u0038_test_version(SG_context * pCtx)
{
	/* This test pokes around in closet internals in ways normal closet callers shouldn't. */

	SG_string* pstrEnv = NULL;
	SG_uint32 len;
	SG_pathname* pPathCloset = NULL;
	SG_pathname* pPathClosetVersion = NULL;
	SG_pathname* pPathClosetVersionBackup = NULL;
	SG_file* pFile = NULL;
	SG_vhash* pvh = NULL;
	
	/* Deliberately making this break for closet version 3 -- current is version 2. */
	SG_byte buf[3]; 
	
	VERIFY_ERR_CHECK(  SG_environment__get__str(pCtx, "SGCLOSET", &pstrEnv, &len)  );
	if (len)
	{
		VERIFY_ERR_CHECK(  SG_PATHNAME__ALLOC__SZ(pCtx, &pPathCloset, SG_string__sz(pstrEnv))  );
	}
	else
	{
		VERIFY_ERR_CHECK(  SG_PATHNAME__ALLOC__USER_APPDATA_DIRECTORY(pCtx, &pPathCloset)  );
		VERIFY_ERR_CHECK(  SG_pathname__append__from_sz(pCtx, pPathCloset, ".sgcloset")  );
	}

	VERIFY_ERR_CHECK(  SG_pathname__alloc__pathname_sz(pCtx, &pPathClosetVersion, pPathCloset, "version")  );
	VERIFY_ERR_CHECK(  SG_pathname__alloc__pathname_sz(pCtx, &pPathClosetVersionBackup, pPathCloset, "version.bak")  );

	VERIFY_ERR_CHECK(  SG_fsobj__move__pathname_pathname(pCtx, pPathClosetVersion, pPathClosetVersionBackup)  );
	
	VERIFY_ERR_CHECK(  SG_file__open__pathname(pCtx, pPathClosetVersion, SG_FILE_OPEN_OR_CREATE|SG_FILE_WRONLY|SG_FILE_TRUNC, 0644, &pFile)  );
	VERIFY_ERR_CHECK(  SG_file__write(pCtx, pFile, sizeof(buf), buf, NULL)  ); 
	VERIFY_ERR_CHECK(  SG_file__close(pCtx, &pFile)  );

	SG_closet__descriptors__list(pCtx, &pvh);
	VERIFY_COND("", SG_context__err_equals(pCtx, SG_ERR_UNSUPPORTED_CLOSET_VERSION));
	SG_ERR_DISCARD;

	VERIFY_ERR_CHECK(  SG_fsobj__remove__pathname(pCtx, pPathClosetVersion)  );
	VERIFY_ERR_CHECK(  SG_fsobj__move__pathname_pathname(pCtx, pPathClosetVersionBackup, pPathClosetVersion)  );

	/* Common cleanup */
fail:
	SG_STRING_NULLFREE(pCtx, pstrEnv);
	SG_PATHNAME_NULLFREE(pCtx, pPathCloset);
	SG_PATHNAME_NULLFREE(pCtx, pPathClosetVersion);
	SG_PATHNAME_NULLFREE(pCtx, pPathClosetVersionBackup);
	SG_FILE_NULLCLOSE(pCtx, pFile);
	SG_VHASH_NULLFREE(pCtx, pvh);
}
int u0001_stdint__test_max(void)
{
	char buf[1024];

	SG_uint8  u8  = SG_UINT8_MAX;
	SG_uint16 u16 = SG_UINT16_MAX;
	SG_uint32 u32 = SG_UINT32_MAX;
	SG_uint64 u64 = SG_UINT64_MAX;

	SG_hex__format_uint8(buf,u8);
	VERIFY_COND("test_max", (strcmp(buf,"ff") == 0));

	SG_hex__format_uint16(buf,u16);
	VERIFY_COND("test_max", (strcmp(buf,"ffff") == 0));

	SG_hex__format_uint32(buf,u32);
	VERIFY_COND("test_max", (strcmp(buf,"ffffffff") == 0));

	SG_hex__format_uint64(buf,u64);
	VERIFY_COND("test_max", (strcmp(buf,"ffffffffffffffff") == 0));


	return 1;
}
Example #24
0
void MyFn(test__parseRfc850)(SG_context *pCtx)
{
	const char *ims = "Tue, 16 Mar 2010 14:11:13 GMT";
	SG_int32 epoch = 1268748673;
	SG_int64 sgtime = (SG_int64)epoch * 1000;
	SG_string *msg = NULL;
	SG_int64 parsed = 0, localparsed;

	SG_ERR_CHECK(  SG_time__parseRFC850(pCtx, ims, &parsed, &localparsed)  );

	SG_ERR_CHECK(  SG_STRING__ALLOC(pCtx, &msg)  );
	SG_ERR_CHECK(  SG_string__sprintf(pCtx, msg, "parsing '%s': expected '%lli', got '%lli'", ims, (long long)sgtime, (long long)parsed)  );

	VERIFY_COND(SG_string__sz(msg), parsed == sgtime);

fail:
	SG_STRING_NULLFREE(pCtx, msg);
}
Example #25
0
void MyFn(test__formatRfc850)(SG_context *pCtx)
{
	const char *expected = "Tue, 16 Mar 2010 14:11:13 GMT";
	SG_int32 epoch = 1268748673;
	SG_int64 sgtime = (SG_int64)epoch * 1000;
	SG_string *msg = NULL;
	char formatted[1024];

	SG_ERR_CHECK(  SG_time__formatRFC850(pCtx, sgtime, formatted, sizeof(formatted))  );

	SG_ERR_CHECK(  SG_STRING__ALLOC(pCtx, &msg)  );
	SG_ERR_CHECK(  SG_string__sprintf(pCtx, msg, "formatting '%lli': expected '%s', got '%s'", sgtime, expected, formatted)  );

	VERIFY_COND(SG_string__sz(msg), strcmp(expected, formatted) == 0);

fail:
	SG_STRING_NULLFREE(pCtx, msg);
}
void MyFn(test1)(SG_context * pCtx)
{
	SG_vector * pVec = NULL;
	SG_uint32 k, ndx, len;
	void * pValue;
	SG_uint32 variable_1 = 0;
	SG_uint32 variable_2 = 0;
#define ADDR_1(k)		((void *)((&variable_1)+k))
#define ADDR_2(k)		((void *)((&variable_2)+k))

	VERIFY_ERR_CHECK(  SG_vector__alloc(pCtx,&pVec,20)  );

	VERIFY_ERR_CHECK(  SG_vector__length(pCtx,pVec,&len)  );
	VERIFY_COND("test1",(len==0));

	for (k=0; k<100; k++)
	{
		// fabricate a bogus pointer from a constant and stuff it into the vector.

		VERIFY_ERR_CHECK(  SG_vector__append(pCtx,pVec,ADDR_1(k),&ndx)  );
		VERIFY_COND("append",(ndx==k));
	}
	for (k=0; k<100; k++)
	{
		VERIFY_ERR_CHECK(  SG_vector__get(pCtx,pVec,k,&pValue)  );
		VERIFY_COND("get1",(pValue == ADDR_1(k)));
	}

	for (k=0; k<100; k++)
	{
		VERIFY_ERR_CHECK(  SG_vector__set(pCtx,pVec,k,ADDR_2(k))  );
	}
	for (k=0; k<100; k++)
	{
		VERIFY_ERR_CHECK(  SG_vector__get(pCtx,pVec,k,&pValue)  );
		VERIFY_COND("get2",(pValue == ADDR_2(k)));
	}

	VERIFY_ERR_CHECK(  SG_vector__length(pCtx,pVec,&len)  );
	VERIFY_COND("test1",(len==100));

	VERIFY_ERR_CHECK(  SG_vector__clear(pCtx,pVec)  );

	VERIFY_ERR_CHECK(  SG_vector__length(pCtx,pVec,&len)  );
	VERIFY_COND("test1",(len==0));

	// fall thru to common cleanup

fail:
	SG_VECTOR_NULLFREE(pCtx, pVec);
}
void u0026_jsonparser__verify(SG_context * pCtx, SG_string* pstr)
{
	const char *psz = SG_string__sz(pstr);
	SG_jsonparser* jc = NULL;
	struct u0026_ctx ctx;

	ctx.key[0] = 0;

	SG_ERR_CHECK(  SG_jsonparser__alloc(pCtx, &jc, u0026_jcb, &ctx)  );

    SG_ERR_CHECK(  SG_jsonparser__chars(pCtx, jc, psz, (SG_uint32) strlen(psz))  );
	if (!SG_context__has_err(pCtx))
	{
		SG_jsonparser__done(pCtx, jc);
		VERIFY_COND("JSON_checker_done", !SG_context__has_err(pCtx));
	}

fail:
	SG_JSONPARSER_NULLFREE(pCtx, jc);
}
Example #28
0
void u0023_vcdiff__do_test_deltify(SG_context * pCtx,
								   SG_pathname* pPath_version1, SG_pathname* pPath_version2)
{
	SG_bool b;
	SG_pathname* pPathDelta = NULL;
	SG_pathname* pPathReconstructed = NULL;

	VERIFY_ERR_CHECK_DISCARD(  unittest__get_nonexistent_pathname(pCtx,&pPathDelta)  );
	VERIFY_ERR_CHECK_DISCARD(  unittest__get_nonexistent_pathname(pCtx,&pPathReconstructed)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_vcdiff__deltify__files(pCtx,pPath_version1, pPath_version2, pPathDelta)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_vcdiff__undeltify__files(pCtx,pPath_version1, pPathReconstructed, pPathDelta)  );

	b = compare_files_are_identical(pPath_version2, pPathReconstructed);
	VERIFY_COND("match after deltify/undeltify", (b));

	SG_ERR_IGNORE(  SG_fsobj__remove__pathname(pCtx,pPathDelta)  );
	SG_ERR_IGNORE(  SG_fsobj__remove__pathname(pCtx,pPathReconstructed)  );

	SG_PATHNAME_NULLFREE(pCtx, pPathDelta);
	SG_PATHNAME_NULLFREE(pCtx, pPathReconstructed);
}
Example #29
0
void MyFn(test1)(SG_context * pCtx)
{
	SG_vector_i64 * pVec = NULL;
	SG_uint32 k, ndx, len;

	VERIFY_ERR_CHECK(  SG_vector_i64__alloc(pCtx,&pVec,20)  );

	VERIFY_ERR_CHECK(  SG_vector_i64__length(pCtx,pVec,&len)  );
	VERIFY_COND("test1",(len==0));

	for (k=0; k<100; k++)
	{
		SG_int64 kValue = (SG_int64)k;
		VERIFY_ERR_CHECK(  SG_vector_i64__append(pCtx,pVec,kValue,&ndx)  );
		VERIFY_COND("append",(ndx==k));
	}
	for (k=0; k<100; k++)
	{
		SG_int64 value;
		VERIFY_ERR_CHECK(  SG_vector_i64__get(pCtx,pVec,k,&value)  );
		VERIFY_COND("get1",(value == ((SG_int64)k)));
	}

	for (k=0; k<100; k++)
	{
		SG_int64 kValue = (SG_int64)k+10000;
		VERIFY_ERR_CHECK(  SG_vector_i64__set(pCtx,pVec,k,kValue)  );
	}
	for (k=0; k<100; k++)
	{
		SG_int64 value;
		VERIFY_ERR_CHECK(  SG_vector_i64__get(pCtx,pVec,k,&value)  );
		VERIFY_COND("get2",(value == ((SG_int64)(k+10000))));
	}

	VERIFY_ERR_CHECK(  SG_vector_i64__length(pCtx,pVec,&len)  );
	VERIFY_COND("test1",(len==100));

	VERIFY_ERR_CHECK(  SG_vector_i64__clear(pCtx,pVec)  );

	VERIFY_ERR_CHECK(  SG_vector_i64__length(pCtx,pVec,&len)  );
	VERIFY_COND("test1",(len==0));

	// fall thru to common cleanup

fail:
	SG_VECTOR_I64_NULLFREE(pCtx, pVec);
}
void MyFn(remove__if)(SG_context* pCtx)
{
	static SG_uint32   uItemCount    = 20u;
	static const char* szItemValue   = "abc";
	static SG_uint32   uStartDivisor = 5u;

	SG_vector* pVector  = NULL;
	SG_uint32  uIndex   = 0u;
	SG_uint32  uCount   = uItemCount;
	SG_uint32  uDivisor = 0u;
	SG_uint32  uRemoved = 0u;

	// create a vector with test data
	VERIFY_ERR_CHECK(  SG_VECTOR__ALLOC(pCtx, &pVector, 10u)  );
	for (uIndex = 0u; uIndex < uItemCount; ++uIndex)
	{
		VERIFY_ERR_CHECK(  SG_vector__append(pCtx, pVector, (void*)szItemValue, NULL)  );
	}

	// run tests, removing every Nth, then every (N-1)th item, etc
	// the last iteration (every 1th item) will remove every remaining item
	for (uDivisor = uStartDivisor; uDivisor > 0u; --uDivisor)
	{
		SG_uint32 uExpected = uCount / uDivisor;

		VERIFY_ERR_CHECK(  SG_vector__remove__if(pCtx, pVector, MyFn(remove__if__predicate), (void*)&uDivisor, &uRemoved, NULL)  );
		VERIFYP_COND("Wrong number of items removed.", uRemoved == uExpected, ("Removed(%u) Expected(%u)", uRemoved, uExpected));

		uCount -= uExpected;
	}
	VERIFY_COND("Expected size should be zero.", uCount == 0u);

	// verify that the vector is empty
	VERIFY_ERR_CHECK(  MyFn(_verify_size)(pCtx, pVector, 0u)  );

fail:
	SG_VECTOR_NULLFREE(pCtx, pVector);
	return;
}