~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/new.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Emscripten tests
 
2
 
 
3
#include <stdio.h>
 
4
#include <stdlib.h>
 
5
#include <assert.h>
 
6
 
 
7
struct Structy { char data[100]; int x; };
 
8
 
 
9
int main() {
 
10
  int NUM = 100;
 
11
  char* allocations[NUM];
 
12
  for (int i = 0; i < NUM/2; i++) {
 
13
    allocations[i] = (char*){{{ NEW }}};
 
14
    assert(allocations[i]);
 
15
    if (i > 10 && i%4 == 1 && allocations[i-10]) {
 
16
      {{{ DELETE }}}(allocations[i-10]);
 
17
      allocations[i-10] = NULL;
 
18
    }
 
19
  }
 
20
  for (int i = NUM/2; i < NUM; i++) {
 
21
    allocations[i] = (char*){{{ NEW }}};
 
22
    assert(allocations[i]);
 
23
    if (i > 10 && i%4 != 1 && allocations[i-10]) {
 
24
      {{{ DELETE }}}(allocations[i-10]);
 
25
      allocations[i-10] = NULL;
 
26
    }
 
27
  }
 
28
  char* first = allocations[0];
 
29
  for (int i = 0; i < NUM; i++) {
 
30
    if (allocations[i]) {
 
31
      {{{ DELETE }}}(allocations[i]);
 
32
    }
 
33
  }
 
34
  char *last = (char*){{{ NEW }}}; /* should be identical, as we free'd it all */
 
35
  char *newer = (char*){{{ NEW }}}; /* should be different */
 
36
  printf("*%d,%d*\n", first == last, first == newer);
 
37
}
 
38